IReport PDF Chinese does not display the problem

IReport PDF Chinese does not display the problem

 

method one:

1. First, when designing a report with iReport, set the properties of the place where Chinese data will be displayed as follows:

  Font name: 宋体(Chinese font)
    PDF font name: STSong-Light
    PDF Encoding: UniGB-UCS2-H(Chinese Siplified)
    PDF Embeded: √

 

2. The iTextAsian.jar package is imported into the classpath of the project. Without this package, the following error will be reported when exporting a PDF containing Chinese data:

net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName   : STSong-Light
pdfEncoding   : UniGB-UCS2-H(Chinese Siplified)

isPdfEmbedded : true

The download address of the iTextAsian.jar package is:

http://sourceforge.net/projects/itext/files/extrajars/ExtraJars1.0/iTextAsian.jar/download

 

Although this method can display Chinese information normally, it has a disadvantage that there is only one font. Because the iTextAsian.jar package provided by the iText official website contains only a few simple Asian fonts, for Simplified Chinese, there is only Song. Therefore, in the PDF generated by this method , the Chinese font can only be Song type, and other fonts cannot be displayed. But this method is simpler

 

Method 2: Use TTF Files (True Type Fonts) font files

 

TTF is the standard font file of the system, originally defined by Mac OS , and later Microsoft Windows generally adopts this format to define font files. This is also our most commonly used font format. Fonts can be specified by formulating specific font files.

如:<font fontName= 隶书 pdfFontName= STCAIYUN.TTF size= 18 isBold= true isPdfEmbedded = true pdfEncoding = Identity-H />

 

In the example, the font " Chinese Caiyun " is used, and STCAIYUN.TTF is the font file. It should be noted that the relative path is used here. When generating the PDF , the program will look for the font file from the classpath. You can choose to put the font file in the classpath, or use the absolute path to refer to the font file. (eg: c:/windows/fonts /STCAIYUN.TTF ). The latter method is not recommended, because the path of the system may be different in the development environment and the usage environment, which will cause the font file to not be found. A better solution is to type some commonly used fonts under fonts in the windows system into a jar package, and then report the jar to the classpath.

 

Note that when using this method, the pdfEncoding attribute should be set to " Identity-H " or " Identity-V " .

 

About iReport

 

For the above two solutions, the first solution can directly select pdfFontName and pdfEncoding in the iReport interface. The system has integrated " STSong-Light " and " UniGB-UCS2-H " , which can be directly selected from the drop-down list.

 

In the second way, there is a fonts directory under the path of iReport , which includes some TTF font files. When selecting pdfFontName in the graphical interface , only font files that exist in the directory can be selected. If you want to use other TTF fonts, you can copy the relevant fonts from the fonts directory of the windows system to the fonts path of iReport , and these fonts will appear in the drop-down list of pdfFontName .

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326646879&siteId=291194637