How ireport and Jasperreport support the text support display

Source: Internet
Author: User
Tags pack

Recently using Grails development program, need to generate a report, I chose to use ireport and as a report generation tool, when the input Chinese is always unable to display normally, my ireport version is 3.7. Later through the online query their own tests, summed up as follows:

The inability to display Chinese is because ireport is using itext to build PDFs, which requires itextasian.jar support. The latest version of ireport has placed Itext and Itextasian in the/report/modeues/ext/directory of the installation directory, but there is no association, and the following actions are required:

1, in the "tool"-"option" select "Classpath", the above two modules included;

2, in the "tool"-"Options" select "Font" in the following PDF fonts path to the above two modules selected;

3, set the report on the display of the relevant properties of the objects, each property settings described below:
Font name: XXFarEastFont-Arial (Chinese font)
PDF Font Name:stsong-light
PDF encoding:unigb-ucs2-h (Chinese siplified)
PDF embeded:√

The following content is reproduced:

Problems that may arise
After the above settings, the report of the Chinese display should be no problem, the author of the report in the development process encountered several problems, is summarized as follows:
3.1 Problem Description
Run iReport1.2.8 in WinXP, design the report by setting the font for the data field to Chinese, compiling and running it after formatting it, and using Jrviewer to preview everything is ok (Chinese appears normal), but using PDF, Excel preview has the following error:
Could not load the following font:
Pdffontname:stsong-light
Pdfencoding:unigb-ucs2-h
Ispdfembedded:true
Reason: into PDF Asian language Pack is not included in the project
Workaround: Include the Asian language pack Itextasian.jar in the item, possibly over ireport "options"  "Classpath" Add Itextasian.jar to the classpath or copy the Itextasian.jar directly to the Lib in the ireport installation directory. If the Web project should copy Itextasian.jar to this project Web-inf/lib In.
3.2 Problem Description
Run iReport1.2.8 in WinXP, design the report to set the font of the data field to Chinese font, adjust the format to compile and run, and use Jrviewer to preview everything is normal (Chinese display normal), use PDF, Excel preview without any errors, but Chinese can not display ( Show Blank only).
Reason: report display object's PDF Font Property set incorrectly
Workaround: The report object's settings for font properties are as follows:
Font name: XXFarEastFont-Arial (Chinese font)
PDF Font Name:stsong-light
PDF encoding:unigb-ucs2-h (Chinese siplified)
PDF embeded:√
The following figure is the method

3.3 Problem Description
When you generate a PDF or Excel file, the Chinese display is normal, but the HTML file appears garbled
The reason: mainly is the page coding problem
Solving method
When you generate HTML in a JSP page, set the <%@ page contenttype= "text/html;charset=gb2312"%>
Response.setcontenttype ("text/html;charset=gb2312") when HTML is generated in the servlet;
If the user of the project has been unified coding settings and filtering, you need to think about it, but it's mostly about coding. For example: The author recently did the project is its in struts, the code for the unification and filtering processing, the generation of HTML page without coding can be correctly generated HTML page, and will not be garbled , if set to charset=gb2312 instead appeared garbled. In short, the coding of the unification and processing is still more annoying things.
In addition, by looking at the ireport generated jrxml (<?xml version= "1.0" encoding= "UTF-8"?>) files, we can find that ireport-saved Chinese characters are UTF-8 encoded. Understanding its coding can help us to unify the coding approach.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.