Home > Java > javaTutorial > body text

How to Avoid \'\' When Rendering Chinese Characters in Apache FOP?

Patricia Arquette
Release: 2024-10-26 11:06:29
Original
190 people have browsed it

How to Avoid

Avoiding #### in Apache FOP When Rendering Chinese Characters

Apache FOP, a popular tool for generating PDF documents, often encounters an issue where Chinese characters are displayed as "####" instead of their intended glyphs. To rectify this problem, three critical steps must be followed:

Step 1: Specify Font-Family in the FO File

Assign the desired font using the font-family property within the FO file. In the example provided, the SimSun font is utilized:

<code class="xml"><fo:block font-family="SimSun">...</fo:block></code>
Copy after login

Step 2: Configure Font Mapping in FOP's Configuration File

In FOP's configuration file (usually fop.xconf), map the font family to the corresponding font file:

<code class="xml"><directory>/Users/furini/Library/Fonts</directory></code>
Copy after login

Or for a specific font mapping:

<code class="xml"><font embed-url="/Users/furini/Library/Fonts/SimSun.ttf">
  <font-triplet name="SimSun" style="normal" weight="normal"/>
</font></code>
Copy after login

Step 3: Point FOP to the Configuration File

When calling FOP from the command line, use the -c option:

$ fop -c /path/to/fop.xconf input.fo input.pdf
Copy after login

From Java code:

<code class="java">fopFactory.setUserConfig(new File("/path/to/fop.xconf"));</code>
Copy after login

By implementing these steps, FOP will render Chinese characters correctly in the generated PDFs. However, if the font file specified in the configuration cannot be found, an error message will be displayed, and the font configuration should be verified.

The above is the detailed content of How to Avoid \'\' When Rendering Chinese Characters in 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!