05.05.2013 Views

Programming PHP

Programming PHP

Programming PHP

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Table 10-3. Standard PDF fonts<br />

Courier Courier-Bold Courier-BoldOblique Courier-Oblique<br />

Helvetica Helvetica-Bold Helvetica-BoldOblique Helvetica-Oblique<br />

Times-Bold Times-BoldItalic Times-Italic Times-Roman<br />

Symbol ZapfDingbats<br />

You can select a font with the pdf_findfont( ) function:<br />

$font = pdf_findfont(pdf, fontname, encoding, embed);<br />

The encoding parameter indicates how the internal numeric codes for characters map<br />

onto the font’s characters. The built-in encodings are "winansi" (Windows, a superset<br />

of ISO 8859-1, which is itself a superset of ASCII), "macroman" (Macintosh),<br />

"ebcdic" (IBM mainframe), "builtin" (for symbol fonts), and "host" ("macroman" on<br />

the Mac, "ebcdic" on EBCDIC-based systems, and "winansi" on everything else).<br />

When using built-in fonts, stick to "host".<br />

You can load nonstandard fonts if you have the PostScript font metrics or TrueType<br />

files. If you want to embed the nonstandard fonts in the PDF file, rather than using<br />

whatever fonts on the viewer’s system most resemble them, set the embed parameter<br />

to 1. You do not need to embed the standard fonts.<br />

Using nonstandard fonts without embedding them makes your documents much less<br />

portable, while embedding them makes your generated PDF files much larger. You<br />

also need to be careful of not violating any font license terms, because some fonts are<br />

not supposed to be embedded. TrueType font files have an indicator that is set if the<br />

font should not be embedded. This is honored by pdflib, which produces an error if<br />

you try to embed such a font.<br />

Embedding Fonts<br />

To use nonstandard fonts, you must tell pdflib where they are with the FontAFM,<br />

FontPFM, orFontOutline parameters. For example, to use a TrueType font, you can<br />

do this:<br />

pdf_set_parameter($p,"FontOutline", "CANDY==/usr/fonts/candy.ttf");<br />

$font = pdf_findfont($p, "CANDY", "host", 1);<br />

The double equals sign in this code tells pdflib that you are specifying an absolute<br />

path. A single equals sign would indicate a path relative to the default font directory.<br />

Instead of using explicit pdf_set_parameter( ) calls each time you want to use a nonstandard<br />

font, you can tell your pdflib installation about these extra fonts by adding<br />

the FontAFM, FontPFM, and FontOutline settings to pdflib’s pdflib.upr file.<br />

Here’s a sample set of additions to the FontAFM and FontOutline sections of the<br />

pdflib.upr file. The line that starts with two slashes (//) indicates the default directory<br />

for font files. The format for the other lines is simply fontname=filename:<br />

244 | Chapter 10: PDF<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2002 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!