Diacritic chars in a Jasper Report template

南笙酒味 提交于 2019-12-23 12:35:01

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/8739811/diacritic-chars-in-a-jasper-report-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!