Avoid problems with fonts not found on Jasper Reports
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.
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:
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).
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.