JasperReports – Packaging fonts to avoid fonts not found

Goal

Avoid problems with fonts not found on Jasper Reports

Description

This recipe explains the easiest and safest way I am aware of to implement a report with Jasper that has no problems of fonts not found on the destination system.

I have never had to work directly with Jasper before because it was someone else on my team that had to do it. Nevertheless, some problems were common in all teams I were member of, namely the ones that relate to fonts not found on the destination environment. Locally, everything worked just fine but, on deployment of the application on the final system, there were some missing fonts that lead to problems on the reports of the application. Today I said to myself that I would no longer have such problems. This recipe summarizes my findings.

How to

What we will do is export the fonts we need (as suggested here) and package them together with our application. Once the fonts are on the classpath of the application, we will no longer have problems related to missing fonts when deploying the application in a given target environment as the application is self sufficient regarding the specification of the fonts it needs!

So, all I need to do is open iReport, go to the option “Tools > Options > Fonts tab”, click the font I use in my reports (I used DejaVu Sans and I had to first install my font on iReport to be able to export it), and click the option “Export as extension”. This will create a jar file with a structure similar to:

  • jasperreports_extension.properties
  • fonts/fontsfamily1373966634065.xml
  • fonts/DejaVuSans.ttf
  • fonts/DejaVuSans-Bold.ttf
  • fonts/DejaVuSans-Oblique.ttf
  • fonts/DejaVuSans-BoldOblique.ttf

And finally, copy the jar file to the classpath of my application (in my case, and although it was a Maven project, I just copied the jar file to the WEB-INF/lib folder).

Explanations

With the necessary fonts on the classpath of the application, there is no need for further configurations on the target environment to make our application work as expected. Therefore, this solution makes it possible for the deployment to be simpler and faster.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s