FOP TTFReader - Build Italic and Bold Fonts


How to build Italic, Bold and Italic-Bold fonts with FOP?



To build Italic, Bold and Italic-Bold fonts with FOP, we need to find their fond files in TTF format.

For example, you see "Calibri", Italic, Bold, and Italic-Bold font files located in \windows\fonts folder:

    813,876 calibri.ttf   > for Calibri,normal,400
    851,480 calibrib.ttf  > for Calibri,normal,700
    856,212 calibrii.ttf  > for Calibri,italic,400
    902,380 calibriz.ttf  > for Calibri,italic,700

You can run FOP TTFReader program to build the "Calibri" font definition files:

\local\fop-2.2\fop>java -cp %FOP_PATH%\build\fop.jar;
   -d \windows\calibri.ttf \fyicenter\calibri.xml

INFO: XML font metrics file successfully created.

Run FOP TTFReader program again to build the "Calibri" Bold, Italic and Italic-Bold font definition files.

Create a new FOP configuration file, cfg-calibri.xml, to all 4 fonts in the same family:

<?xml version="1.0"?>
<!-- cfg-calibri.xml
     Copyright (c) 2018
<fop version="1.0">
    <renderer mime="application/pdf">
        ="\fyicenter\calibri.xml" kerning="no" 
          <font-triplet name="Calibri" style="normal" weight="normal"/>
        <font metrics-url="\fyicenter\calibrii.xml" kerning="no" 
          <font-triplet name="Calibri" style="italic" weight="normal"/>
        <font metrics-url="\fyicenter\calibrib.xml" kerning="no" 
          <font-triplet name="Calibri" style="normal" weight="bold"/>
        <font metrics-url="\fyicenter\calibriz.xml" kerning="no" 
          <font-triplet name="Calibri" style="italic" weight="bold"/>

Generate the PDF output again from the FO file, You will see no font missing error:

\local\fop-2.2\fop>fop \fyicenter\ \temp\calibri-bold-italic.pdf
   -c \fyicenter\cfg-calibri.xml processEvent
INFO: Rendered page #1.

Open the PDF output file, calibri-bold-italic.pdf in Acrobat Reader. You see all 4 fonts are working correctly now:
FOP Font Family, Bold and Italic, for PDF

This tutorial is valid in FOP 2.2, 2.1, and 2.0.


FontView.exe - Preview Font Glyphs on Windows

FOP Missing Italic and Bold Fonts for PDF

Managing Fonts in FOP PDF Output

⇑⇑ FAQ for FOP (Formatting Object Processor)

2018-04-12, 124👍, 0💬