Jump to content
Changes to the Jaspersoft community edition download ×

generate pdf contain Chinese


shrimpy

Recommended Posts

Code:

JRPdfExporter jasperPdfExportMgr = new JRPdfExporter();

ByteArrayOutputStream pdfReport = new ByteArrayOutputStream();
jasperPdfExportMgr.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);
jasperPdfExportMgr.setParameter(JRExporterParameter.START_PAGE_INDEX, 0);
jasperPdfExportMgr.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8"«»);
jasperPdfExportMgr.setParameter(JRExporterParameter.OUTPUT_STREAM, pdfReport);

FontKey key = new FontKey("Arial", false, false);
PdfFont font = new PdfFont("STSong-Light", "UniGB-UCS2-V", false);
Map<Object, Object> fontMap = new HashMap<Object, Object>();
fontMap.put(key, font);

jasperPdfExportMgr.setParameter(JRExporterParameter.FONT_MAP, fontMap);

jasperPdfExportMgr.exportReport();

 

I want to generate a pdf which will contain Chinese charactors, i read some post in this forum, and try to follow , but in my pdf file, why the Chinese charactor do not show in really Chinese, instead of some unknow charactors... for example 姓å, it display like this "jUn*^9", something i don`t know what is it!!!!!

 

anybody can help ....plzzzzzzzzzzzzzzzzzzzzzz

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Code:

<font fontName="Arial" pdfFontName="STSong-Light" size="10" isBold="true" isItalic="false" isUnderline="false" isPdfEmbedded ="true" pdfEncoding ="UniGB-UCS2-H" isStrikeThrough="false" />

 

i don`t know what else i can do now....

i configure in my codes,

and do configuration in the jrxml file..

 

man...anybody can tell me what should i do next....really drive me crazy......

Link to comment
Share on other sites

Hi,

 

I think you should embed the Chinese font into PDF by setting the last PdfFont constructor parameter to "true".

 

PdfFont font = new PdfFont("STSong-Light", "UniGB-UCS2-V", true);

 

Otherwise you are counting on the font being installed on the machine that displays the PDF, which is probably not the case, hence the problem.

Also, make sure you add the iTextAsian.jar to your classpath. You can find it here:

http://sourceforge.net/project/showfiles.php?group_id=15255&package_id=151860

 

I hope this helps.

Teodor

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...