13

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Vishal
  • 131
  • 1
  • 4
  • Do the fonts used for export have the characters necessary? I'm not sure what method Jasper Report uses, but the PDF file usually contains the font used for generating it - which means that font must support international characters. – Piskvor left the building Feb 23 '11 at 16:33
  • http://maryniuk.blogspot.com/2010/09/custom-ttf-fonts-in-jasperreports.html this helped me –  Jun 22 '11 at 06:28

5 Answers5

10

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>
mist
  • 1,853
  • 2
  • 19
  • 33
Ru5
  • 821
  • 9
  • 6
  • 3 years later... pdfEncoding is deprecated however jasperreports-fonts uses font-extensions if you like to use your own font, see http://stackoverflow.com/questions/34041619/jasper-reports-pdf-doesnt-export-cyrillic-values/ for font-extension example. – Petter Friberg Jan 18 '16 at 17:04
8

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:

  • your text is using one of the above style names
  • you have the ttf files on the classpath

That should do it (I'm taking the code from a working cyrilic application)

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
2
  1. register font in JVM

    Font myFont = Font.createFont(Font.TRUETYPE_FONT, new File("pathToCyrillicFont"));
    GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(myFont); 
    
  2. add to Cyrillic field this:

    <textElement>
       <font
                      fontName="fontName"
                      pdfFontName="pathToCyrillicFont"
                      size="13"
                      isBold="false"
                      isItalic="false"
                      isUnderline="false"
                      isPdfEmbedded ="true"
                      pdfEncoding ="Cp1251"
                      isStrikeThrough="false"
       /> 
     </textElement>
    

Enjoy!

user1958322
  • 101
  • 6
2

Since jasper report v5, v6 the correct way to display characters in pdf is to use font-extension

For more information see these question on stackoverflow:

Jasper Reports PDF doesn't export cyrillic values

How can I display "$£Ω€απ⅔" in Jasperserver PDF using iReport?

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
0

just stumbled over this, the solution for me was to add the font-resource on the server. Go to you report -> edit -> add Resources

womd
  • 3,077
  • 26
  • 20