While implementing a report in Jasper Reports, it is likely to miss the portability aspect. Portability in case of reports?! you could ask. Yes, portability. Do you know that the same report can look differently when generated on Windows, Linux and OS X? It may because of the same reason why a web page looks slightly different when opened on different operating systems. The culprits are fonts. A report generated on Windows may use different fonts than when it is generated on Linux. The reason is simple – Windows fonts might not be available on Linux and JasperReports use those that are available.
Why fonts are different
During report generation, Jasper Server or JasperReports Library uses fonts that are available on the system where it is installed. Unfortunately, fonts are often not free to use, like Arial. That is the reason why Linux does not have it. There might be other similar fonts available, but they are not exactly the same so you may sometimes notice a difference in a way letters look like or line breaking, problems with the report layout may emerge etc. It is interesting to check fonts equivalents between Windows and OS X. It is clearly visible how big the issue is.
If reports are always generated on the same OS, the problem might remain invisible. But if JasperReports Server or an application with JasperReports Library is installed on various operating systems , the issue will probably show up.
Ways to make fonts look the same
One of the solutions is to make sure the fonts used by reports are exactly the same on all systems where reports are generated. That is theoretically easy, because font formats like TrueType (.ttf) are portable. So they (like Arial) technically could be copied from Windows to Linux. Technically, but it is illegal. Arial is a commercial font so it would have to be purchased. You got it with Windows but you are not allowed to copy it to other systems or computers. Buying a license for a set of fonts could be a way to go.
It might be worth to mention that Microsoft decided to share the most popular fonts for free in a project called Core fonts for the Web, so they could have been used but they gave up on it in 2002. The library with the fonts can still be found on the internet, but as you can guess – it is out dated.
The best option in my opinion is to find a font that is free to use. There are many websites where fonts can be found:
- http://www.1001freefonts.com/
- http://www.dafont.com/
- http://www.fontsquirrel.com/
- http://www.1001fonts.com/
A number of free fonts is enormous but if you want to use a font that is similar to those that users are used to, it is not easy to find one. After spending some time in the subject, I noticed that the majority of the fonts I see everyday like Arial, Helvetica, Times New Roman are commercial fonts.
Once a free font is chosen and downloaded there are at least two options to make it working with Jasper.
- The font can be installed on all systems where the reports are going to be generated. It might be problematic if you would like to distribute your application that produces those reports. But if it is only you who hosts the reports generator, that could work.
- The font can be attached to the application so wherever it is deployed, the fonts are available for JasperReports Library.