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, you have to find out the name of a font that has the glyphs for the special characters you used. One font that covers the majority of 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 CMD=java -cp "$LIB/fop.jar:$LIB/avalon-framework-4.2.0.jar:$LIB/xercesImpl.jar" export CMD=$CMD org.apache.fop.fonts.apps.TTFReader export FONT_DIR='/Library/Fonts' $CMD $FONT_DIR/Arialuni.ttf Arialuni.xml
For Windows create a file ttfConvert.bat:
set LIB=lib set CMD=java -cp "%LIB%\fop.jar;%LIB%\avalon-framework-4.2.0.jar;%LIB%\xercesImpl.jar" set CMD=%CMD% 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 Author plugin installation directory so if you decide to create it in other directory you have to change the file paths accordingly.
The FONT_DIR can be different on your system. Make sure it points to the correct font directory. If the Java executable is not in the PATH you will have to specify the full path of the executable.
If the font has bold and italic variants, you will have to convert those too. For this you add 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. You have to 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>