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.
- get the utf-8 fonts and place them on your classpath
- for older jasper-reports version use a custom
style
and apply it to all texts - 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
精彩评论