View page as PDF

Adding type faces to Apache FOP

This section contains detailed instructions for how to add type faces to Apache FOP for PDF generation in Cocoon 1.7.1 on a Windows system. The links below provide additional information:

The following example creates the Garamond type face. First, go to the “lib” directory of Cocoon


Then, consider the typeface creation command:

java -cp
-enc ansi C:\WINDOWS\Fonts\gara.ttf
  1. First, the command should be entered on one line (not several lines, as in this example).
  2. Second, you have to manually check that the Jar files are actually in the directories used in the command (in a sub-directory below “lib”, that is).
  3. Third, you have to check that the name of the .jar files are correct. They sometimes change for instance version number.
  4. Then, you have to check where your font files are, and what their files names are (this example only works for true-type files), and use the path to the type faces on your system.
  5. You also have to create the FOP-FONTS directory (at some convenient location).


This example creates garamond regular, bold, italic. Again, remember that the output should be in different xml files for each type face. Also, no line breaks when you enter the commands.

java -cp optional\fop-0.20.5.jar;endorsed\xercesImpl-2.6.2.jar;endorsed\xml-apis.jar org.apache.fop.fonts.apps.TTFReader -enc ansi C:\WINDOWS\Fonts\gara.ttf E:\fop-fonts\garamond.ttf.xml
java -cp optional\fop-0.20.5.jar;endorsed\xercesImpl-2.6.2.jar;endorsed\xml-apis.jar org.apache.fop.fonts.apps.TTFReader -enc ansi C:\WINDOWS\Fonts\garabd.ttf E:\fop-fonts\garamondbd.ttf.xml
java -cp optional\fop-0.20.5.jar;endorsed\xercesImpl-2.6.2.jar;endorsed\xml-apis.jar org.apache.fop.fonts.apps.TTFReader -enc ansi C:\WINDOWS\Fonts\garait.ttf E:\fop-fonts\garamondi.ttf.xml

You could remove the ”–enc ansi” part of the command, but then your font metrics will be CID-keyed. At this time, that will not work (you will not be able to copy text from your pdf document).


Then create a config.xml file (if you have a type face named “config”, then obviously you have to use a different file name) in your fop-fonts directory.

Here is an example file:

<?xml version="1.0" encoding="UTF-8"?>
<font metrics-file="E:/fop-fonts/garamond.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GARA.TTF">
<font-triplet name="Garamond" style="normal" weight="normal"/>
<font metrics-file="E:/fop-fonts/garamondbd.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GARABD.TTF">
<font-triplet name="Garamond" style="normal" weight="bold"/>
<font metrics-file="E:/fop-fonts/garamondi.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GARAIT.TTF">
<font-triplet name="Garamond" style="italic" weight="normal"/>
<font metrics-file="E:/fop-fonts/arial.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<font-triplet name="ArialMT" style="normal" weight="normal"/>
<font metrics-file="E:/fop-fonts/arialbd.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/arialbd.ttf">
<font-triplet name="Arial" style="normal" weight="bold"/>
<font-triplet name="ArialMT" style="normal" weight="bold"/>
<font metrics-file="E:/fop-fonts/arialbi.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/arialbi.ttf">
<font-triplet name="Arial" style="italic" weight="bold"/>
<font-triplet name="ArialMT" style="italic" weight="bold"/>
<font metrics-file="E:/fop-fonts/ariali.ttf.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/ariali.ttf">
<font-triplet name="Arial" style="italic" weight="normal"/>
<font-triplet name="ArialMT" style="italic" weight="normal"/>
<font metrics-file="E:/fop-fonts/GIL_____.TTF.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GIL_____.TTF">
<font-triplet name="Gill Sans" style="normal" weight="normal"/>
<font-triplet name="Gill Sans MT" style="normal" weight="normal"/>
<font metrics-file="E:/fop-fonts/GILI____.TTF.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GILI____.TTF">
<font-triplet name="Gill Sans" style="italic" weight="normal"/>
<font-triplet name="Gill Sans MT" style="italic" weight="normal"/>
<font metrics-file="E:/fop-fonts/GILB____.TTF.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GILB____.TTF">
<font-triplet name="Gill Sans" style="normal" weight="bold"/>
font-triplet name="Gill Sans MT" style="normal" weight="bold"/>
<font metrics-file="E:/fop-fonts/GILBI___.TTF.xml" kerning="yes" embed-file="C:/WINDOWS/Fonts/GILBI___.TTF">
<font-triplet name="Gill Sans" style="italic" weight="bold"/>
<font-triplet name="Gill Sans MT" style="italic" weight="bold"/>


Then, you also have to alter your sitemap. Replace the following section:

<map:serializer name="fo2pdf"

Main menu bar