Using TrueType Fonts for StyleVision PDF Generation
The following solution and download files will enable Apache FOP users to make TrueType fonts available for PDF generation in StyleVision.
In order for StyleVision to utilize your TrueType fonts, the following prerequisites must be met:
- FOP compliant option must be active.
- One metrics file must be present for each TrueType font that is used by the PDF document.
- The Apache FOP configuration file must contain information that maps a font family name to its TTF and metrics files.
Activating the FOP compliant option in StyleVision
You can activate this option in the Options Dialog; it is called “FOP 0.93 compliant” in StyleVision 2017.
Creating the TrueType font metrics files
A metrics file is created by calling the Java application TTFReader. TTFReader is included with Apache FOP, so if you have Apache FOP installed, TTFReader is already installed, too.
If you are proficient in calling a Java application, you can call TTFReader yourself to create the metrics file for each TrueType font. Alternatively, we have provided a set of command files below that ease this task. With these command files, you can easily create metrics files for all the TrueType fonts installed on your computer.
- Download the necessary command line scripts for this exercise here. (1.45 KB)
- Copy the GenerateMetricsFileSingle.cmd and GenerateMetricsFileAll.cmd files into the same directory that holds your FOP folder (this will be C:\Program Files\Altova for users who downloaded the FOP installer from the Altova Web site).
- Using a text editor, open the GenerateMetricsFileSingle.cmd file.
- For each .jar file referenced in GenerateMetricsFileSingle.cmd, check that the version number contained in the file name matches the version number of the corresponding file in your FOP installation folder. Modify the version number in the file name if necessary.
- Open a Command Prompt window and run GenerateMetricsFileAll.cmd.
- When the command completes, there will be a folder “C:\Font Metrics” containing a number of .xml files; these are the metrics files for the TTF fonts.
Modifying the Apache FOP configuration file
The Apache FOP configuration file is named fop.xconf and is located in the folder “conf” below the FOP installation folder. It is an XML file and contains several <font> elements that are commented out by default:
<font metrics-url="arial.xml" kerning="yes" embed-url="arial.ttf"> <font-triplet name="Arial" style="normal" weight="normal"/> <font-triplet name="ArialMT" style="normal" weight="normal"/> </font>
For each TTF file your PDF file will contain, add one <font> element. In each element, substitute the correct information for the font.
In the example above,
|arial.xml||is the name of the metrics file|
|arial.ttf||is the name of the TTF file (usually located in %WINDIR%\Fonts).|
|Arial||specifies that the above metrics and TTF files will be used if the font family name in StyleVision is defined as “Arial”.|
|style="normal"||specifies that the above metrics and TTF files will be used if the font style in StyleVision is defined as “normal” (not “italic”).|
|weight="normal"||specifies that the above metrics and TTF files will be used if the font weight in StyleVision is defined as “normal” (not “bold”).|
When the configuration file is complete, it needs to be supplied with the actual call to Apache FOP. In a text editor, open the file fop.bat (located in the Apache FOP installation folder) and change the last line from