Apache FOP Chinese Character Display Issues
When using Apache FOP to print PDF documents, Chinese characters may appear as "####" despite having the necessary language files installed. This issue is caused by a lack of font support in the default configuration.
To resolve this issue, three steps are required:
Step 1: Specify Font Family in FO File
Indicate the desired font using the font-family property. For example:
<fo:block font-family="SimSun">博洛尼亚大学中国学生的毕业论文</fo:block>
Step 2: Configure Font Mapping in FOP's Configuration File
In fop.xconf, add font mappings to the font file:
<font> <font-triplet name="SimSun" style="normal" weight="normal"/> <embed-url>/path/to/SimSun.ttf</embed-url> </font>
Or you can add a directory to map all fonts in that directory:
<directory>/path/to/Fonts</directory>
Step 3: Reference Configuration File
Use the -c option when calling FOP from the command line:
$ fop -c /path/to/fop.xconf input.fo input.pdf
From Java code, use setUserConfig().
Once all three steps are complete, Chinese characters should be displayed correctly in the PDF document.
The above is the detailed content of How to Display Chinese Characters Correctly in PDF Documents Using Apache FOP?. For more information, please follow other related articles on the PHP Chinese website!