When creating PDF reports that contains for example Asian characters you
might need to configure the Apache FOP system to find proper fonts that
contains glyphs for those characters.
As mentioned in earlier chapter, the report generator contains two
different version of Apache FOP: 0.20.5 and 1.0. The font handling in
the latter version has been improved a lot compared to earlier versions.
This version should preferably be used.
The sub chapters below contain information how to define custom fonts
for the different FOP versions.
|
In your stylesheet, you need to refer to the fonts that
contain the proper glyphs.
|
<xsl:attribute-set name="tableCell">
<xsl:attribute name="font-family">MSMincho</xsl:attribute> (1)
...
</xsl:attribute-set>
...
<fo:table-cell xsl:use-attribute-sets="tableCell"> (2)
<fo:block>
...
</fo:block>
</fo:table-cell>
1 |
Defines the font |
2 |
Use attribute set |
1.1. FOP 0.20.5
Create a file called FOPConfig-0.20.5.xml
within the folder:
/WEB-INF/classes/com/technia/tvc/reportgenerator/fop
To register custom fonts, add them into the file created according to
the example below:
<configuration>
<fonts>
<!-- example -->
<!--
<font metrics-file="arial.xml" kerning="yes" embed-file="arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
<font-triplet name="ArialMT" style="normal" weight="normal"/>
</font>
<font metrics-file="arialb.xml" kerning="yes" embed-file="arialb.ttf">
<font-triplet name="Arial" style="normal" weight="bold"/>
<font-triplet name="ArialMT" style="normal" weight="bold"/>
</font>
<font metrics-file="ariali.xml" kerning="yes" embed-file="ariali.ttf">
<font-triplet name="Arial" style="italic" weight="normal"/>
<font-triplet name="ArialMT" style="italic" weight="normal"/>
</font>
<font metrics-file="arialbi.xml" kerning="yes" embed-file="arialbi.ttf">
<font-triplet name="Arial" style="italic" weight="bold"/>
<font-triplet name="ArialMT" style="italic" weight="bold"/>
</font>
-->
<!-- Example Japanese fonts
<font metrics-file="msgothic.xml" embed-file="D:\winnt\font\msgothic.ttc" kerning="yes">
<font-triplet name="Gothic" style="normal" weight="normal"/>
<font-triplet name="Gothic" style="normal" weight="bold"/>
<font-triplet name="Gothic" style="italic" weight="normal"/>
<font-triplet name="Gothic" style="italic" weight="bold"/>
</font>
<font metrics-file="msmincho.xml" embed-file="Cyberbit.ttf" kerning="yes">
<font-triplet name="Mincho" style="normal" weight="normal"/>
<font-triplet name="Mincho" style="normal" weight="bold"/>
<font-triplet name="Mincho" style="italic" weight="normal"/>
<font-triplet name="Mincho" style="italic" weight="bold"/>
</font>
-->
</fonts>
</configuration>
-
The metrics-file must be created from the TTF file using the below command: (example below)
java -cp tvc-reportgenerator-x.y.z.jar com.technia.tvc.fop0205.fonts.apps.TTFReader [options] C:\myfonts\cmr10.ttf ttfcm.xml
Where the [options]
are described in the table below:
Option |
Description |
|
By default, FOP uses the fontname from the .pfm file
when embedding the font. Use the "-fn" option to override this name with
one you have chosen. This may be useful in some cases to ensure that
applications using the output document (Acrobat Reader for example) use
the embedded font instead of a local font with the same name.
|
|
If you’re reading data from a TrueType
Collection (.ttc file) you must specify which font from the collection
you will read metrics from. If you read from a .ttc file without this
option, the fontnames will be listed for you.
|
|
Creates a WinAnsi-encoded font metrics file. Without this
option, a CID-keyed font metrics file is created. The table below
summarizes the differences between these two encoding options as
currently used within FOP. Please note that this information only
applies to TrueType fonts and TrueType collections:
|
-
The metrics files are located relative to the root of the
application.
-
Some additional info on this topic can be read from this resource:
1.2. FOP 1.0+
As of FOP 1.0, the fonts available in the operating system on the server
where the report generator is running will be registered automatically.
If you need to register a new font, do as described below:
-
Create a file called FOPConfig.xml within the folder:
/WEB-INF/classes/com/technia/tvc/reportgenerator/fop
-
The default file that is part of the envoiareportgenerator.jar looks like below:
<fop version="1.0">
<strict-configuration>false</strict-configuration>
<strict-validation>false</strict-validation>
<source-resolution>72</source-resolution>
<target-resolution>72</target-resolution>
<use-cache>true</use-cache>
<renderers>
<renderer mime="application/pdf">
<fonts>
<auto-detect/>
</fonts>
</renderer>
</renderers>
</fop>
Modify this file according to the descriptions found at this URL: