I was developing a telecommunication bill using Jasper Studio (V6.0.4) on Windows and Jasper Server (V6.0.1) which was remotely hosted on an Ubuntu server. Jasper Studio was used to design layout while Jasper Server was in charge of generating final bill. All worked fine until I tried to expert a PDF version of the bill. The issue was because the bill had characters other than English (Chinese in this case), PDF could not embed those non-ANSI fonts so there was no Chinese shown on exported PDF while everything looked fine in Jasper Studio. The error messages I received include following:

“net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font: xxx”

I tried all methods I could find on Google (such as installing iText Asian pack, installing fonts on my Ubuntu server which hosts Jasper) but none of them worked. I guess it’s because they were all based on iReport which is outdated by now (or an old version of Jasper Server).

I read all Jasper documents including the ultimate guide but they didn’t help either. After a couple of days search, I finally came to this Wiki page on Jasper community:

http://community.jaspersoft.com/wiki/custom-font-font-extension

After a quick try, this solution worked perfectly!

Instead of repeating all steps described in the Wiki here again, I just want to highlight certain points:

  1. Source the font (for testing/development, you can copy from C:Windowsfonts, but in production ensure you don’t violate copy right.)
  2. Create font extension in Jasper Studio (Preferences -> fonts ->Add). Choose “Identity-H” for “PDF encoding” (this is for Chinese, choose others where applicable) and tick “Embed this font in PDF document”. Note Jasper Studio/Server embeds fonts that were used only (to reduce file size of the PDF) therefore you will need to keep the font file in a folder that is also accessible for other projects if you re-use this font extension.
  3. Export the font extension (Preferences -> fonts ->Export)
  4. Add the extension back to the project ( project Properties -> Java Build Path -> Libraries -> Add External JARs). By doing this you ensure your project can always embed the font when exporting to PDF.
  5. On Jasper Server, do similar thing to upload the font Extension so on the Server, PDF can be exported as well.
  6. Now in Jasper Studio, for any static text, you can choose the new font. (If it doesn’t appear, restart Jasper Studio)

 

Comparing to iReport, obviously the font-extension solution is much clearer as this extension(JAR) can be distributed along with any other projects and you don’t need to worry about font and its configuration every time.

Jasper report server

Leave a Reply

Your email address will not be published. Required fields are marked *

31 + = 34

This site uses Akismet to reduce spam. Learn how your comment data is processed.