I am trying to display ukranian character in jasper report as a pdf file. but it is not diaplaying in pdf format.
when I export report to all other format like html, csv..ukranian char is displaying.
Set some text field properties at iReport. Use font DejaVu Sans. Set pdf encoding to Cp1251 and isPdfEmbedded to true.
Ex.: <font fontName="DejaVu Sans" isStrikeThrough="false" pdfEncoding="Cp1251" isPdfEmbedded="true" />
jasperreports fonts as maven dependency:
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
</dependency>
First, make sure you have the right encoding:
JRPdfExporter exporter = new JRPdfExporter();
exporter.setParameter(JRExporterParameter.CHARACTER_ENCODING, "UTF-8");
Then you should change the fonts to ones that support cyrillic. This is done via styles:
public void addPdfFontsToStyles(JRStyle[] styles) {
if (styles != null) {
for (JRStyle style : styles) {
if (style.getName().equals("reportStyle")) {
style.setPdfFontName("/com/yourcompany/fonts/times.ttf");
style.setBlankWhenNull(true);
}
if (style.getName().equals("reportBoldStyle")) {
style.setPdfFontName("/com/yourcompany/fonts/timesbd.ttf");
style.setBlankWhenNull(true);
}
}
}
}
And invoke this method with addPdfFontsToStyles(jasperReport.getStyles());
Of course, the prerequisites are:
That should do it (I'm taking the code from a working cyrilic application)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With