Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
752 views
in Technique[技术] by (71.8m points)

java - Jasper Reports PDF doesn't export cyrillic values

I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.

enter image description here

The code I use to export is:

JRExporter e = new JRPdfExporter();
                e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
                e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
                e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);

I even tried to specift the parameter below:

e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");

but did not succeed. Any suggestions?

Question&Answers:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:

  1. Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
  2. Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
  3. Is my font embedded so that if I share the pdf also computers not having this font can display the content?

How can I ensure this is JasperReport?

The deprecated method was to set attributes on the textElement

<textElement>
  <font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
  <paragraph lineSpacing="Single"/>
</textElement>

The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.

How to generate font extension .jar using iReport or JasperSoft Studio.

EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...