JasperReports, Tomcat, and Fonts
One of our clients uses JasperReports, attached to a headless system running Tomcat and an interesting little module that ties things into a Drupal installation for remote interaction/management. This is not the story of that Drupal module.
Rather, it's a simple explanation about what needs to happen to use a new font with Jasper on a Linux system. The client needed some new reports, and wanted a shiny new font to go with them. After Googling for a bit on Jasper and fonts, no matter what I tried, I was greeted with the following:
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font :
pdfFontName : RockwellStd
pdfEncoding : Cp1252
isPdfEmbedded : false
RockwellStd was the font in question, by the way. Right, well, using an external font is rather simple. First, put the font somewhere. Anywhere, really.
Then, just modify your report (.jrxml file) wherever you need to call the font:
<font fontName="Verdana" pdfFontName="/opt/jdk1.6.0_03/jre/lib/fonts/RockwellStd.otf"
size="10" isBold="false" isPdfEmbedded ="true"/>
The important parts of this are pdfFontName and isPdfEmbedded. pdfFontName should be the entire path to the font, including the font's filename. Then set isPdfEmbedded to true, since you'll want the font embedded.
That's it. It's stupidly simple, requires no messing about with installation of fonts on Linux, and puzzled me for far longer than I'd like to admit.