4

I have to use Polish language to fill my report content, so I have to use diacritic chars (ą, ć, ę, ł, ó, ż, ź). And I have problem with them, they are skipped after exporting jasper print to an output. When I write in a template "lubię żółwie" (means "I like turtles" in Polish), an output pdf contains only "lubi wie" (btw it means "he likes he knows" - so it changes a lot ;)). Even there are no empty spaces in place of missing letters. They are just skipped.

An additional hint is it doesn't matter if those string are static text in the report or dynamic $P{}

My question is: "How to make them appear"?

I was trying (without success):

  1. Using method setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8") of JRPdfExporter
  2. Setting JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "UTF-8");
  3. Setting JRProperties.setProperty("net.sf.jasperreports.export.character.encoding", "UTF-8");
  4. Putting REPORT_LOCALE into parameter map (JasperFillManager.fillReport)

SOLUTION: It turend out that in my case it's enough to attach a font to class path, define own jasperreports_extension.properties and fonts.xml. Details here. If somebody uses Grails framework to do it (like me) here is more accurate example. Addidtional and required step is setting JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250") as Wojtek wrote. Still don't know why but I'll update the solution when I know an answer.

Community
  • 1
  • 1
emstol
  • 5,966
  • 6
  • 27
  • 32
  • Did you check export in iReport? What export did you use (pdf, xls, doc)? – Alex K Jan 05 '12 at 09:52
  • Yes, I checked. It looks OK. I use pdf. – emstol Jan 05 '12 at 10:06
  • The font you used should support diacritic chars. You can read about the [font extensions](http://jasperforge.org/uploads/publish/jasperreportswebsite/trunk/sample.reference/fonts/index.html#fontextensions) – Alex K Jan 05 '12 at 10:52
  • Thx Alex, the font extensions hint was valuable. I'd vote up your answer if you posted it as an answer. – emstol Jan 05 '12 at 15:01

1 Answers1

3

If you are working on a Windows machine:

Inside your JasperReports jar archive you will find a configuration file called default.jasperreports open it and change the value of the following property as follows:

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

You can also use:

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

but I think the first solution is cleaner. Please also make sure that the pdf font of your field supports diacritic chars as Alex K noted. AFAIK those fonts are bolded out in the font selection combobox.

If you would like to use UTF-8 fonts with your report, you would have to place them on your classpath first and include them explicitly.

Wojciech Owczarczyk
  • 5,595
  • 2
  • 33
  • 55
  • Setting the PDF font was deprecated 3 years ago. It's MUCH better to use font extensions. – mdahlman Jan 05 '12 at 18:25
  • Hello Wojtek. I've revised solution with font extensions once more and it's not enough. After setting net.sf.jasperreports.default.pdf.encoding=Cp1250 as you wrote it started working. Do you know why I need exactly Cp1250? Strings in my model are utf-8, a jasper template (jrxml) is utf-8. So why cp1250? I'm a Java/Linux guy, and I'm afraid that the cp1250 will get revenge on me later. – emstol Jan 09 '12 at 09:39
  • I assume that the machine hosting the JVM which triggers report creation is Linux-based? – Wojciech Owczarczyk Jan 09 '12 at 15:49