6

I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.

enter image description here

The code I use to export is:

JRExporter e = new JRPdfExporter();
                e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
                e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
                e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);

I even tried to specift the parameter below:

e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");

but did not succeed. Any suggestions?

Alex K
  • 22,315
  • 19
  • 108
  • 236
Nick Gun
  • 67
  • 1
  • 1
  • 4
  • The output result is here: http://snag.gy/ip5F7.jpg – Nick Gun Dec 02 '15 at 11:29
  • You need to add font extension similar problem http://stackoverflow.com/questions/33940126/how-can-i-display-%C2%A3%E2%84%A6%E2%82%AC%CE%B1%CF%80%E2%85%94-in-jasperserver-pdf-using-ireport. Please let us know if after adding font extension (Idenity-H, embedded) you have still have problems – Petter Friberg Dec 02 '15 at 12:00
  • What does my issue have to do with adding font extension to iReport or JasperSoft? My export is done through java code executing the jasper report. Nevertheless, the dependency for jasperreports-fonts is specified in maven as well – Nick Gun Dec 02 '15 at 12:19
  • IReport or JasperSoft was only indicate as a tool to generate the jar (check point 3 and 4 of the answer) of the font-extensions that need's to be included in your java code.. But if you are sure you have the correct font-extension (with included .ttf font supporting your chars.) included in your project I guess that this is not the problem, but I will still bet on font-extension problem.... – Petter Friberg Dec 02 '15 at 12:30
  • I suggest that you edit your question, with your fontsFamily.xml and your jasperreports_extension.properties indicating which .ttf you are using. (and if where the .ttf can be downloaded) – Petter Friberg Dec 02 '15 at 12:38
  • I am using Tahoma font – Nick Gun Dec 02 '15 at 12:39
  • and you are familiar to how to create the fontsFamily.xml and that you need to bundle the .ttf font? – Petter Friberg Dec 02 '15 at 12:40
  • I wasn't until you pointed it out :) Actually now as I changed the font to DejaVu Sans the values displayed correctly. Your point is correct. Thanks a lot. You can answer the question – Nick Gun Dec 02 '15 at 12:42
  • Did you use iReport or JasperSoft Studio, to include a .jar or did you manually include the files and .ttf in your project? Need to know otherwise I don't know how to answer – Petter Friberg Dec 02 '15 at 12:46
  • I used JasperSoft to create the report. I designed and set the fonts in JasperSoft. Then in my project I included jasper dependencies and did the business logic. I am supplying data source as bean and therefore I can only run the report through my project by supplying the jrdatabeansource. I didn't do any custom font. When changed from tahoma to DejaVu it worked – Nick Gun Dec 02 '15 at 12:54
  • You probably have a problem with fonts. Look for answer to this post: [configuration of jasperreports for cyr text](http://stackoverflow.com/questions/33808348/jasper-ireport-3-7-6-font-style-not-rendering-in-pdf/33808543#33808543) – shcherbak Dec 02 '15 at 13:23
  • Is "DejaVu Sans" the only possible font to use? I used the default one (SansSerif) and after switching to "DejaVu Sans" the same lines look much longer and do not fit to their containers. – Sasha Shpota Mar 05 '19 at 12:24

1 Answers1

9

Jasper report uses iText and always when a char is not rendered in pdf this should be the checklist:

  1. Is my actual .tff supported (OpenType) and can the font actually render the character. Not all fonts render all characters in UTF-8, see How can I test if my font is rendered correctly in pdf?
  2. Do I pass correct encoding to iText. In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.
  3. Is my font embedded so that if I share the pdf also computers not having this font can display the content?

How can I ensure this is JasperReport?

The deprecated method was to set attributes on the textElement

<textElement>
  <font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
  <paragraph lineSpacing="Single"/>
</textElement>

The current non deprecated method v 3-6, is to add Font Extensions and this is easily achieved by using tools like iReport or JasperSoft Studio that can generate a .jar of your font extension so that you can include it in your classpath directly.

How to generate font extension .jar using iReport or JasperSoft Studio.

EDIT: The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.

Graham
  • 7,431
  • 18
  • 59
  • 84
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109