问题
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):
- Using method
setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8")
ofJRPdfExporter
- Setting
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "UTF-8");
- Setting
JRProperties.setProperty("net.sf.jasperreports.export.character.encoding", "UTF-8");
- 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