14 Built-in Fonts
Courier | Courier-Bold |
Courier-Oblique | Courier-BoldOblique |
Helvetica | Helvetica-Bold |
Helvetica-Oblique | Helvetica-BoldOblique |
Times-Roman | Times-Bold |
Times-Italic | Times-BoldItalic |
Symbol | ZapfDingbats |
You can also use other AFM fonts, postscript type-1 and TTF fonts. To use a TTF font,
for example:
<?php
PDF_set_parameter($p,"FontOutline",
"CANDY==/usr/fonts/candy.ttf");
$font = PDF_findfont($p,"CANDY","host",1);
?>
CANDY Font Example
Fonts can also be defined in the pdflib.upr file.
Character Encodings
winansi | Windows code page 1252,a superset of ISO 8859-1 |
macroman | Mac Roman encoding,i.e.,the default Macintosh character set |
ebcdic | EBCDIC code page 1047 as used on IBM AS/400 and S/390 systems |
builtin | Original encoding used by non-text (symbol) or non-Latin text fonts |
host | Macroman on the Mac,ebcdic on EBCDIC-based systems,and winansi on all other |
Font Example
<?php
$p = PDF_new();
PDF_open_file($p);
PDF_set_info($p,"Creator","hello.php");
PDF_set_info($p,"Author","Rasmus Lerdorf");
PDF_set_info($p,"Title","Hello world (PHP)");
pdf_set_parameter($p, "resourcefile", "/usr/share/fonts/pdflib/pdflib.upr");
PDF_begin_page($p,595,842);
PDF_set_text_pos($p,25,800);
$fonts = array('Courier'=>0,'Courier-Bold'=>0,'Courier-BoldOblique'=>0,
'Courier-Oblique'=>0,'Helvetica'=>0,'Helvetica-Bold'=>0,
'Helvetica-BoldOblique'=>0,'Helvetica-Oblique'=>0,
'Times-Bold'=>0,'Times-BoldItalic'=>0, 'Times-Italic'=>0,
'Times-Roman'=>0, 'LuciduxSans'=>1,'Utopia-Regular'=>1,
'URWGothicL-BookObli'=>1, 'URWPalladioL-Roma'=>1,
'NimbusMonL-ReguObli'=>1,'CANDY'=>1, 'Arial'=>1
);
foreach($fonts as $f=>$embed) {
$font = PDF_findfont($p,$f,"host",$embed);
PDF_setfont($p,$font,25.0);
PDF_continue_text($p,"$f (".chr(128)." Ç à á â ã ç è é ê)");
}
PDF_end_page($p);
PDF_close($p);
$buf = PDF_get_buffer($p);
$len = strlen($buf);
Header("Content-type:application/pdf");
Header("Content-Length:$len");
Header("Content-Disposition:inline; filename=hello_php.pdf");
echo $buf;
PDF_delete($p);
?>
Output
The pdflib.upr file entries for this would look like this:
FontAFM
LuciduxSans=lcdxsr.afm
Utopia-Regular=UTRG____.afm
URWGothicL-BookObli=a010033l.afm
URWPalladioL-Roma=p052003l.afm
NimbusMonL-ReguObli=n022023l.afm
FontOutline
LuciduxSans=lcdxsr.pfa
Utopia-Regular=UTRG____.pfa
URWGothicL-BookObli=a010033l.pfa
URWPalladioL-Roma=p052003l.pfa
NimbusMonL-ReguObli=n022023l.pfa
CANDY=CANDY.ttf
Arial=arial.ttf