Many users have encountered the issue of Chinese characters displaying as "####" in PDF documents generated using Apache FOP. Resolving this issue involves a three-step process.
Firstly, it is necessary to specify the desired font-family in the FO file. By default, FOP uses the Helvetica font, which may not support Chinese characters. To specify a different font, such as SimSun, include the following line in the FO file:
...
However, this alone may not be sufficient to resolve the issue. FOP also requires a configuration to map the specified font-family to the actual font file. This configuration is specified in FOP's configuration file, typically located at conf/fop.xconf. Add the following lines to the configuration file:
/path/to/fonts
This informs FOP to automatically configure all font files within the specified directory. Alternatively, you can specify the font mapping explicitly for each font-family and style combination:
Finally, specify the configuration file when invoking FOP. From the command line, use the -c option:
fop -c /path/to/fop.xconf input.fo input.pdf
Or, if using FOP from Java code:
fopFactory.setUserConfig(new File("/path/to/fop.xconf"));
By following these steps, FOP will have the necessary information to correctly display Chinese characters with the SimSun font in generated PDF documents.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3