FOP Auto-Detecting Fonts

This section provides a tutorial example on how to configure Apache FOP to auto detect fonts from Windows system.

Earlier in the book, we learned that XSL processors are required to map XSL-FO generic fonts to specific fonts based output devices. In this tutorial, let's take a look at how Apache FOP does this for PDF output files:

1. By default, FOP only supports 3 XSL-FO generic fonts: sans-serif, serif and monospace. They are automatically mapped to Adobe Base-14 fonts: Helvetica Times and Courier.

2. FOP does support font definitions through a configuration file. But you have to create one and invoke it explicitly. A sample of FOP configuration file is located at \fop\conf\fop.xconf. The FOP command to invoke a configuration file looks like this:

C:\herong>\fop\fop -fo -pdf abc.pdf -c \fop\conf\fop.xconf

3. FOP can be configured to auto-detect fonts from Windows system, by adding the following setting to the fop.xconf file:

<fop ...>
  <renderer mime="application/pdf">

The above setting tells FOP to auto-detect fonts from Windows system.

We can verify this with the following tutorial example,, to verify the configuration:

<?xml version="1.0" encoding="utf-8"?>
 - Copyright (c) 2016,, All Rights Reserved.
<fo:root xmlns:fo="">
  <fo:simple-page-master master-name="page" 
   margin="0.1in" page-height="4.4in" page-width="3.4in">
   <fo:region-body region-name="body"/>
 <fo:page-sequence master-reference="page">
  <fo:flow flow-name="body" font-size="12pt">
<fo:block margin-top="6pt">sans-serif font:
 <fo:inline background-color="#ffddff" 
  font-family="sans-serif" font-weight="bold">
The tangram is a dissection puzzle consisting of seven flat shapes, 
called tans, which are put together to form shapes.
<fo:block margin-top="6pt">Tahoma font:
 <fo:inline background-color="#ffddff" 
  font-family="Tahoma" font-weight="bold">
The tangram is a dissection puzzle consisting of seven flat shapes, 
called tans, which are put together to form shapes.

If you process this example XSL-FO document with Apache FOP without the configuration file and with the configuration file, you will see the difference:

C:\herong>\local\fop\fop -fo
   -pdf Apache-FOP-Auto-Detect-Fonts_fop.pdf
... processEvent
WARNING: Font "Tahoma,normal,700" not found. 
Substituting with "any,normal,700".

... processEvent
INFO: Rendered page #1.

C:\herong>\local\fop\fop -fo
   -pdf Apache-FOP-Auto-Detect-Fonts_fop.pdf
   -c \fop\conf\fop.xconf

... processEvent
INFO: Rendered page #1.

As you can see, without the configuration file, FOP returns an error, because it can not find the Tahoma font. With the configuration file, FOP generates the PDF file with no problem, because it auto detected the Tahoma font on the Windows system.

If you open the PDF output file, Apache-FOP-Auto-Detect-Fonts_fop.pdf, in Adobe Acrobat Reader, you will see two blocks of text displayed in two fonts. Tahoma font is obviously thicker (or bolder) than sans-serif.

If you click File > Properties > Fonts, you will see 3 fonts are used in this PDF file:

The picture below shows you the font differences and the font property list in Arcobat Reader:

Apache FOP Auto-Detected Fonts

Last update: 2016.

Table of Contents

 About This XSL-FO Tutorial Book

 Introduction of XSL-FO

 Apache™ FOP (Formatting Objects Processor)

 RenderX XEP as an XSL-FO Tool

 Introduction of Area Model

 XSL-FO Document Basics and Examples

 Page Layout Masters

 Block-Level Formatting Objects

 Inline-Level Formatting Objects

 Including Graphics in XSL-FO document

 Table of Rows and Columns

 List, Item, Label, and Body

 Floating Blocks - "float" and "footnote"

 Hyperlinks, Table of Contents and Indexes

 Headers and Footers using "static-content"

 Font Attributes and Font Families

Apache FOP Font Configurations

FOP Auto-Detecting Fonts

 Using SimHei Font for Chinese Characters

 RenderX XEP Font Configurations


 PDF Printing Version