(mis)adventures in software development...

30 August 2011

JasperReports Font Foibles

Category Programming

One moment I’m thinking JasperReports is great, it’s exactly what I need, it’s making things so easy and my job/life/world is all the better for it. The next moment I find I’ve overlooked/forgotten/misunderstood some arcane aspect of it and everything degenerates into a horrible, broken, useless mess, and I’m thinking why am I bothering with all this when it just seems to be an exercise in endless frustration and misery? Kind of like some past relationships. It’s as if we’re dating.

The latest frustration is fonts. After much time spent creating a particularly “dense” report, with lots of fields, lots of data, and much time spent meticulously tweaking so that everything lines up and is spaced out appropriately while still fitting in all the data and displaying properly, I upload the final project to the production server, only to find this particular report no longer displays properly — some of the fields are truncated. WTF? I checked this. Many times. It was all working properly on my machine. What’s different between my machine and the production machine? Java and JasperReports versions are the same. Turns out the production machine is running RedHat Linux, while I am developing on Ubuntu. Looks like it’s a fonts thing. I was using Java logical fonts for the reports. Seems there is no guarantee even between different Linux distributions that these fonts will map to the same (size) physical font. And seems there are more hoops to jump through to be absolutely sure of getting the right font in a PDF report.