| Transforming Documents / XSL-FO Processors | |
If an XML document is transformed to PDF using the built-in Apache FOP processor but it contains some Unicode characters that cannot be rendered by the default PDF fonts, then a special font that is capable to render these characters must be configured and embedded in the PDF result.
First, find out the name of a font that has the glyphs for the special characters you used. One font that covers most characters, including Japanese, Cyrillic, and Greek, is Arial Unicode MS.
On Windows the fonts are located into the C:\Windows\Fonts directory. On Mac, they are placed in /Library/Fonts. To install a new font on your system, is enough to copy it in the Fonts directory.
For Mac OS X and Linux create a file ttfConvert.sh:
#!/bin/sh export LIB=lib export CP=$LIB/fop.jar export CP=$CP:$LIB/avalon-framework-4.2.0.jar export CP=$CP:$LIB/xercesImpl.jar export CP=$CP:$LIB/commons-logging-1.1.1.jar export CP=$CP:$LIB/commons-io-1.3.1.jar export CP=$CP:$LIB/xmlgraphics-commons-1.5.jar export CP=$CP:$LIB/xml-apis.jar export CMD="java -cp $CP org.apache.fop.fonts.apps.TTFReader" export FONT_DIR='.' $CMD $FONT_DIR/Arialuni.ttf Arialuni.xml
For Windows create a file ttfConvert.bat:
@echo off set LIB=lib set CP=%LIB%\fop.jar set CP=%CP%;%LIB%\avalon-framework-4.2.0.jar set CP=%CP%;%LIB%\xercesImpl.jar set CP=%CP%;%LIB%\commons-logging-1.1.1.jar set CP=%CP%;%LIB%\commons-io-1.3.1.jar set CP=%CP%;%LIB%\xmlgraphics-commons-1.5.jar set CP=%CP%;%LIB%\xml-apis.jar set CMD=java -cp "%CP%" org.apache.fop.fonts.apps.TTFReader set FONT_DIR=C:\Windows\Fonts %CMD% %FONT_DIR%\Arialuni.ttf Arialuni.xml
The paths specified in the file are relative to the Oxygen XML Developer installation directory. If you decide to create it in other directory, change the file paths accordingly.
The FONT_DIR can be different on your system. Check that it points to the correct font directory. If the Java executable is not in the PATH, specify the full path of the executable.
If the font has bold and italic variants, convert them too by adding two more lines to the script file:
$CMD $FONT_DIR/Arialuni-Bold.ttf Arialuni-Bold.xml $CMD $FONT_DIR/Arialuni-Italic.ttf Arialuni-Italic.xml
%CMD% %FONT_DIR%\Arialuni-Bold.ttf Arialuni-Bold.xml %CMD% %FONT_DIR%\Arialuni-Italic.ttf Arialuni-Italic.xml
<fop version="1.0">
<base>./</base>
<font-base>file:/C:/path/to/FOP/font/metrics/files/</font-base>
<source-resolution>72</source-resolution>
<target-resolution>72</target-resolution>
<default-page-settings height="11in" width="8.26in"/>
<renderers>
<renderer mime="application/pdf">
<filterList>
<value>flate</value>
</filterList>
<fonts>
<font metrics-url="Arialuni.xml" kerning="yes"
embed-url="file:/Library/Fonts/Arialuni.ttf">
<font-triplet name="Arialuni" style="normal"
weight="normal"/>
</font>
</fonts>
</renderer>
</renderers>
</fop>
The embed-url attribute points to the font file to be embedded. Specify it using the URL convention. The metrics-url attribute points to the font metrics file with a path relative to the base element. The triplet refers to the unique combination of name, weight, and style (italic) for each variation of the font. In our case is just one triplet, but if the font had variants, you would have to specify one for each variant. Here is an example for Arial Unicode if it had italic and bold variants:
<fop version="1.0">
...
<fonts>
<font metrics-url="Arialuni.xml" kerning="yes"
embed-url="file:/Library/Fonts/Arialuni.ttf">
<font-triplet name="Arialuni" style="normal"
weight="normal"/>
</font>
<font metrics-url="Arialuni-Bold.xml" kerning="yes"
embed-url="file:/Library/Fonts/Arialuni-Bold.ttf">
<font-triplet name="Arialuni" style="normal"
weight="bold"/>
</font>
<font metrics-url="Arialuni-Italic.xml" kerning="yes"
embed-url="file:/Library/Fonts/Arialuni-Italic.ttf">
<font-triplet name="Arialuni" style="italic"
weight="normal"/>
</font>
</fonts>
...
</fop>
More details about the FOP configuration file are available on http://xmlgraphics.apache.org/fop/0.93/configuration.htmlthe FOP website.
<renderer mime="application/pdf">
. . .
<fonts>
<font metrics-url="Arialuni.xml" kerning="yes"
embed-url="file:/Library/Fonts/Arialuni.ttf">
<font-triplet name="Arialuni" style="normal"
weight="normal"/>
</font>
</fonts>
. . .
</renderer>
XML Author.