Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jasper reports with PDF and Unicode (greek) characters

I have a very strange problem: I am trying to export a Jasper report containing Unicode characters (greek) as a PDF. My problem is that a specific greek character (the character delta) is printed in a different font face from the one I am using (Arial) !

The following image is copied from the exported pdf:

i dont like this

While the following image is the same text from MS Word using the same font:

this is much better

As you can see, the third letter (delta) is different from the others. This happens ONLY for this letter, for all font sizes. I also tried to change the font to garamond, but still got the same problem with exactly the same letter !

Finally, I should add that the internal preview from iReport is ok, also ok is the export to other formats like docx or html ...

Update 20/04/11: I also tried to open the pdf with Foxit reader portable - but had exactly the same behaviour as with Adobe Acrobat Reader.

Update 28/04/11: I have created a snippet in pastebin that generates the problem when exported to pdf. One warning - you have to "install" the font you will use (Arial in my case) through "Options - Fonts" of iReport or else you won't be able to see anything at all in the pdf.

Update 05/03/13 SOLUTION: Well since there are people (probably from Greece) that still have the same problem and view this question, I'd like to make another update: I started using again Jasper reports, however now I am using a newer version of Jasper (Jasper 5) and iReport (iReport 5). Everything is working ok now -- no problematic deltas in PDFs :) So just try upgrading your iReport and Jasper libraries if you experience the same problem !!

Update 05/04/13 Final Comments: After two years, I was able to work again on the system with the problematic greek character (delta) and was able to draw some final conclusions about the problem: So, first I upgraded the version of Jasper we were using to 5.x and still experienced the problem ! The problem was fixed only when I changed the included font extension (.jar) with a new one that I created (exported) from iReport 5.x. So, the problem was that when exporting the font extension, iReport 3.x (which was used to export the old extension) didn't export the greek character delta correctly, while iReport 5.x exports it fine. So my suggestion is still true: Any people having this problem upgrade your Jasper version to 5.x but also re-export your font extensions through iReprot 5.x. I really hope I won't do any more updates to this :)

like image 881
Serafeim Avatar asked Apr 19 '11 11:04

Serafeim


People also ask

How do I use a custom font in Jasper report?

The basic elements of adding a custom font to a Jasper report are: Go get the font files you want to use ( TTF, EOT, SVG or WOFF (OTF converted to TTF works as well)) Add the fonts to Jaspersoft Studio (or iReport) using the UI. Now you can preview the font in your report.

How do I create a style template in Jasper report?

Open a report, right click on the Styles node into the Outline View and select "Create Style Template".


2 Answers

Font extensions. The answer is font extensions. (The answer is always font extensions.)

When I run your report I get a different result: I don't see any of the Greek characters. I can solve it by changing the font. Or I can solve it by adding Arial as a Font Extension. (Or I could probably solve it by putting Arial into the classpath somewhere... but don't do that. It's asking for trouble.) I wrote about font extensions a while back. They were created to solve this type of issue. That's what you should use.

Because the report behaved differently for me, I'm only mostly sure that this is the answer. Let us know.

like image 185
mdahlman Avatar answered Oct 12 '22 02:10

mdahlman


In case anybody comes looking, I came across a similar problem, when generating PDF files from PHP and FPDF. In my case, the problem (and solution) was : When FPDF generates a font info file (font.php) via MakeFont, it creates a /Differences encoding sequence (as defined in PDF specs) which is then embedded in the PDF file. The /Differences sequence uses names from the "Adobe Glyph List", (http://partners.adobe.com/public/developer/en/opentype/glyphlist.txt) which is NOT the same as the Unicode glyph names... Looking at this list, I found the following entries :

Delta;2206
Deltagreek;0394  <-- this is the correct unicode point

the FPDF library was using the "Delta" name, which (I think) is meant to display the mathematical "delta" symbol.

By patching the generated .php font info file, and changing 'Delta' to 'Deltagreek', the problem was solved. You only need to do this once, per font info file.

While the above is valid for PDF and FPDP and PHP, I suspect that you are having the same problem with Jasper. You need to check how Jasper handles encodings, etc.

Hope this helps somebody :)

like image 31
mike Avatar answered Oct 12 '22 03:10

mike