开发者

Jasper Report PDF Encoding

I am trying to generate or export to PDF a jasper report but I can't display nihongo or japanese开发者_StackOverflow中文版 characters. How do I fix this.


You can also set "net.sf.jasperreports.default.pdf.encoding" in code like this:

JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");


Update

From the comment: 6 years later, the correct way to display character in Jasper Reports is using font-extensions, e.g. see https://stackoverflow.com/a/33941102/254109

Original answer

Make a file jasperreports.properties, put it in the class path and set the PDF encoding.

net.sf.jasperreports.default.pdf.encoding=Cp1250

Or make base style in a report, set what you need, and all other styles derive from this style, i.e. they have an attribute style="base".


You have to embed UTF-8 fonts in the PDF.

  1. get the utf-8 fonts and place them on your classpath
  2. for older jasper-reports version use a custom style and apply it to all texts
  3. before printing, call style.setPdfFontName("/com/package/fonts/times.ttf");

For newer versions the PdfFontName is deprecated instead of another way of doing this, but I can't find it now - look it up yourself.

Another workaround might be found here


I have faced same issue but with Eastern European characters. When i set a pdfEncoding property to Cp1250 then it started to work but unfortunately it didn't worked for french characters. Then I found this article which provides a very easy solution: http://jasperstarter.sourceforge.net/unicode-pdf-export.html

it was enough to set fontName="DejaVu Sans"


Below approach will address indic font issues. http://jasperreports.sourceforge.net/sample.reference/fonts/index.html#fontextensions

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜