FOP Missing Italic and Bold Fonts for PDF

Q

Why I am getting the 'Font "Calibri,normal,700" not found. Substituting with "Calibri,normal,400"' error with FOP?

✍: FYIcenter.com

A

You are getting the "Font X,normal,700 not found. Substituting with X,normal,400" error, if FOP can not find the "Bold" font definition for the font X.

Computer fonts are usually defined as a family of minimum 4 fonts: Normal, Bold, Italic and Bold-Italic. So that you can the font in 4 variations as shown in this FO file, calibri-bold-italic.fo:

```<?xml version="1.0" encoding="utf-8"?>
<!-- calibri-bold-italic.fo
Copyright (c) 2018 FYIcenter.com
-->
<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
<fo:layout-master-set>
<fo:simple-page-master master-name="myPage">
<fo:region-body margin="1in"/>
</fo:simple-page-master>
</fo:layout-master-set>
<fo:page-sequence master-reference="myPage">
<fo:flow flow-name="xsl-region-body">
<fo:block font-family="Calibri">Calibri: Welcome to jar.FYIcenter.com!</fo:block>
<fo:block font-family="Calibri" font-weight="bold">
Calibri Bold: Welcome to jar.FYIcenter.com!</fo:block>
<fo:block font-family="Calibri" font-style="italic">
Calibri Italic: Welcome to jar.FYIcenter.com!</fo:block>
<fo:block font-family="Calibri" font-weight="bold" font-style="italic">
Calibri Bold and Italic: Welcome to jar.FYIcenter.com!</fo:block>
</fo:flow>
</fo:page-sequence>
</fo:root>
```

If you try to generate the PDF output with only the normal "Calibri" font defined, you will get errors as shown below:

```\local\fop-2.2\fop>fop \fyicenter\calibri-bold-italic.fo \temp\calibri-bold-italic.pdf
-c \fyicenter\cfg-font.xml

org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Calibri,normal,700" not found. Substituting with "Calibri,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Calibri,italic,400" not found. Substituting with "Calibri,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
WARNING: Font "Calibri,italic,700" not found. Substituting with "Calibri,normal,400".
org.apache.fop.events.LoggingEventListener processEvent
INFO: Rendered page #1.
```

Notice that how a font is identified with 3 parameters: font family name, style and weight. For example, "Calibri,normal,700" identifies the "normal" style font with "700 (bold)" weight from the "Calibri" font family.

To resolve the issue, we need to build 3 more font definition files for "Calibri Bold", "Calibri Italic", and "Calibri Italic Bold".

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

2018-04-12, 839👍, 0💬