XSL-FO Tutorials - Herong's Tutorial Examples - Version 2.10, by Dr. Herong Yang
Using SimHei Font for Chinese Characters
This section provides a tutorial example on how to use SimHei font family to support Chinese characters with Apache FOP.
In the last tutorial, we learned that Apache FOP can be configured to auto-detect fonts from Windows system. That means we can use any fonts that are available on Windows system.
Now let's see if we can find and use Windows font to support Chinese characters.
1. Run Windows Character Map tool to find a font that support Chinese characters:
C:\herong>charmap
2. On the Character Map window, select "SimHei" from the font dropdown list. Then scroll down on the character list to confirm Chinese characters are supported.
3. Use the following tutorial example, Apache-FOP-SimHei-Chinese-Font.fo, to try it:
<?xml version="1.0" encoding="utf-8"?> <!-- Apache-FOP-SimHei-Chinese-Font.fo - Copyright (c) 2016, HerongYang.com, All Rights Reserved. --> <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> <fo:layout-master-set> <fo:simple-page-master master-name="page" margin="0.1in" page-height="4.4in" page-width="3.4in"> <fo:region-body region-name="body"/> </fo:simple-page-master> </fo:layout-master-set> <fo:page-sequence master-reference="page"> <fo:flow flow-name="body" font-size="10pt"> <fo:block margin-top="6pt">English letters: <fo:inline background-color="#ffddff" font-family="sans-serif" font-weight="bold"> The tangram is a dissection puzzle consisting of seven flat shapes, called tans, which are put together to form shapes. </fo:inline> </fo:block> <fo:block margin-top="6pt">Chinese characters: <fo:inline background-color="#ffddff" font-family="SimHei" font-weight="bold"> 七巧板是一種智力游戏,顧名思義,七巧板是由七塊板組成的。由於等積變換, 所以這七塊板可拼成許多圖形(千種以上)。 </fo:inline> </fo:block> </fo:flow> </fo:page-sequence> </fo:root>
If you process this example XSL-FO document with Apache FOP tool to generate a PDF file, you will see a warning:
... org.apache.fop.events.LoggingEventListener processEvent WARNING: Font "SimHei,normal,700" not found. Substituting with "SimHei,normal,400". ... org.apache.fop.events.LoggingEventListener processEvent INFO: Rendered page #1.
Not too bad. FOP could not find SimHei 700 (bold). But it found SimHei 400 and used it instead. The PDF output is acceptable as shown below:
Last update: 2016.
Table of Contents
About This XSL-FO Tutorial Book
Apache™ FOP (Formatting Objects Processor)
XSL-FO Document Basics and Examples
Block-Level Formatting Objects
Inline-Level Formatting Objects
Including Graphics in XSL-FO document
Floating Blocks - "float" and "footnote"
Hyperlinks, Table of Contents and Indexes
Headers and Footers using "static-content"
Font Attributes and Font Families
►Apache FOP Font Configurations
►Using SimHei Font for Chinese Characters