Home > Java > javaTutorial > body text

How to Display Chinese Characters Correctly in PDF Documents Using Apache FOP?

Susan Sarandon
Release: 2024-10-26 11:37:02
Original
640 people have browsed it

How to Display Chinese Characters Correctly in PDF Documents Using Apache FOP?

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>
Copy after login

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>
Copy after login

Or you can add a directory to map all fonts in that directory:

<directory>/path/to/Fonts</directory>
Copy after login

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
Copy after login

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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!