HOWTO: Install custom fonts
Back to table of contents
Keep in mind that most likely you will be using FPDF output method, as it covers 90% of your needs.
Installing fonts for PDFLIB and Postscript output methods is required only if you're using
non-default output driver.
- FPDF
- Postscript
- Postscript (PS2PDF)
- PDFLIB
FPDF output method
Let's assume that you're going to install Trebuchet MS for the FPDF output method.
- Copy font files (trebuc.ttf, treducdb.ttf, trebucbi.ttf and trebucit.ttf)
to TTF_FONTS_REPOSITORY directory (by default it points to 'fonts' subdirectory)
- Generate font metrics file for these fonts files
and put it into the same directory. Note that metrics file should have the same name as font file and
extension .afm (this step is optional if you're using a html2ps version more recent than 1.9.4)
- Register new font family in html2ps.config: add the following lines to html2ps.config in
the FONTS-PDF section (between <fonts-pdf> and </fonts-pdf> tags):
<family name="Trebuchet MS">
<normal normal="TrebuchetMS" italic="TrebuchetMS-Italic" oblique="TrebuchetMS-Italic"/>
<bold normal="TrebuchetMS-Bold" italic="TrebuchetMS-Bold-Italic" oblique="TrebuchetMS-Bold-Italic"/>
</family>
-
Register font files: add the following to the FONTS-PDF section:
<ttf typeface="TrebuchetMS" embed="0" file="trebuc.ttf"/>
<ttf typeface="TrebuchetMS-Bold" embed="0" file="trebucbd.ttf"/>
<ttf typeface="TrebuchetMS-Italic" embed="0" file="trebucit.ttf"/>
<ttf typeface="TrebuchetMS-Bold-Italic" embed="0" file="trebucbi.ttf"/>
Note that you may want to replace embed="0" with embed="1" if you intend
to distribute generated PDF to users without Trebuchet MS font installed in their machines.
Postscript output method
Say you want to see the fancy "Trebuchet MS" font in your generated
postscript...
- First of all, TrueType-compatible Ghostscript is a must. Most Ghostscipt
distributions are TrueType compatible. If you're not sure, ask your system
administrator. If your GS is not True-Type compatible, consider building from
source using require options.
- Find the file coresponding to "Trebuchet MS". Assuming you're
using some version of Windows on your home machine, you can do it by opening
"Control Panel ... Fonts" and checking the properties of the chosen
font. At the top of the property page you'll see the file name - trebuc.ttf,
in our case.
- Find the font files corresponding to the bold, italic and bold italic versions
of this font. Probably, it will be:
"Trebuchet MS Bold" -- trebucbd.ttf,
"Trebuchet MS Italic" -- trebucit.ttf,
"Trebuchet MS Bold Italic" -- trebucbi.ttf
- Copy these files from the Windows fonts directory (probably C:\Windows\Fonts)
to the Ghostscript fonts directory (probably C:\gs\fonts).
- Modify the Ghostscript fontmap file (probably C:\gs\gs8.51\lib\Fontmap,
assuming you're using Ghostscript version 8.51), adding the folowing lines:
/TrebuchetMS (trebuc.ttf) ;
/TrebuchetMS-Italic (trebucit.ttf) ;
/TrebuchetMS-Bold (trebucbd.ttf) ;
/TrebuchetMS-Bold-Italic (trebucbi.ttf) ;
Note you can write almost anything after the / assuming it won't interfere
with other font names. Say:
/MyCoolFont1 (trebuc.ttf) ;
/MyCoolFont2 (trebucit.ttf) ;
/MyCoolFont3 (trebucbd.ttf) ;
/MyCoolFont4 (trebucbi.ttf) ;
- Register the above font names in the script config file. Add the following
lines to html2ps.config in the FONTS section (between <fonts>
and </fonts> tags)
<family name="Trebuchet MS">
<normal normal="TrebuchetMS" italic="TrebuchetMS-Italic" oblique="TrebuchetMS-Italic"/>
<bold normal="TrebuchetMS-Bold" italic="TrebuchetMS-Bold-Italic" oblique="TrebuchetMS-Bold-Italic"/>
</family>
Of course, the modified file should be uploaded to the server where the working
script reside.
- Register the metric files of the new TrueType fonts. To do it, add the following to the FONT section:
<metrics typeface="TrebuchetMS" file="trebuc"/>
<metrics typeface="TrebuchetMS-Italic" file="trebucit"/>
<metrics typeface="TrebuchetMS-Bold" file="trebucbd"/>
<metrics typeface="TrebuchetMS-BoldItalic" file="trebucbi"/>
In this case, the "file" value refers to the name of the font metric file (.afm) you've
generated. The ".afm" extension
as appended automatically; files are searched in the directory specified by TYPE1_FONTS_REPOSITORY configuration
constant (see your config.inc.php file).
- Now, the following example should be rendered using Trebuchet MS font:
<BIG style="font-family: 'Trebuchet MS'">ABCDEFGH</BIG><br>
<BIG style="font-family: 'Trebuchet MS'; font-weight: bold;">ABCDEFGH</BIG><br>
<BIG style="font-family: 'Trebuchet MS'; font-style: italic;">ABCDEFGH</BIG><br>
<BIG style="font-family: 'Trebuchet MS'; font-weight: bold; font-style: italic;">ABCDEFGH</BIG><br>
PS2PDF output method
Take the steps described above with only this difference: all Ghostscript-related
directories are on your server where the script resides. Ask your hoster/system
administrator about the exact location of Ghostscript.
PDFLIB output method
Please refer to PDFLib Documentation.