7

I am trying to generate or export to PDF a jasper report but I can't display nihongo or japanese characters. How do I fix this.

Peter Butkovic
  • 11,143
  • 10
  • 57
  • 81
cedric
  • 3,107
  • 15
  • 54
  • 65

5 Answers5

12

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

JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");
zigomir
  • 985
  • 2
  • 15
  • 30
  • I can not say it louder: thank you. I was fooling around with things like JRPropertiesUtil.getInstance(context).setProperty()... A good advice though is to use jaspers property constants: http://jasperreports.sourceforge.net/api/constant-values.html And if you by any chance already have the possibility to hav a charset in your hands(eg: "windows-1250"), you can use the org.apache.xmlbeans.impl.common.EncodingMap.getIANA2JavaMapping(yourcharset) to get the analog "CP1250". – chris polzer Sep 19 '14 at 11:22
  • coming very late , but as 'JRProperties.setProperty' is deprecated and 'JRPropertiesUtil.getInstance(context).setProperty()' is not working do you have another solution – Emad Mar 03 '17 at 08:38
9

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".

Vy Do
  • 46,709
  • 59
  • 215
  • 313
xmedeko
  • 7,336
  • 6
  • 55
  • 85
  • I have added `jasperreports.properties` with mentioned contents, somethings started to come but now it is showing "?" characters. Please help me on this. – Atul Kumar Oct 16 '14 at 07:24
  • 1
    6 years later, the correct way to display character in jasper report is using font-extensions see for example http://stackoverflow.com/questions/33940126/how-can-i-display-%C2%A3%E2%84%A6%E2%82%AC%CE%B1%CF%80%E2%85%94-in-jasperserver-pdf-using-ireport/ – Petter Friberg Jan 18 '16 at 17:08
5

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

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
4

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"

Marian Ban
  • 8,158
  • 1
  • 32
  • 45
1

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

Logesh
  • 11
  • 1