How to Change Fonts in Openbravo Reports
The objective of this article is to show you how to change the fonts used in Openbravo Reports. This can be useful in two cases:
- We want to create our reports with a prettier or more readable appearance
- Some character sets like Japanese, Arabic or Vietnamese cannot be be displayed or printed out with the fonts used by default in the standard reports, so replacing the default font for one
that supports those character sets is the solution to properly display the reports in those languages.
Before reading this guide, it is necessary to have a proper understanding of Openbravo's Modularity concept and how to create and package a module,
as we take the knowledge from these articles as a given in this guide.
In case you are working with reports on a regular basis, the following link to an article might be of interest to you, since it describes how to create a report.
Openbravo uses two different tools to create reports:
- Jasper Reports
With this, we need a different approach for each tool to change the font of the reports being generated by them. Both approaches will of course be explained here:
Changing the font in Jasper Reports
When changing the font in Jasper Reports, the software Jaspersoft Studio will be very helpful.
In the following link you can find a detailed tutorial that describes how to handle custom fonts in Jaspersoft Studio. In short, these are the steps we need to carry out:
- 1. Get the desired font's .ttf file from your pc or from the Internet.
- 2. Create the Font Extension, go to Window > Preferences
- 3. Click on JasperSoft Studio > Fonts. Click Add. At this point you must provide a unique name for the Font Extension and the path to its extension by selecting the path of the downloaded .ttf file.
- 4. Once done, we set a PDF Encoding type for our new font in the wizard.
- 5. We now have to change the fontName and pdfFontName used in the text fields we want to have being displayed with the new font in our report. We can accomplish that by either using Jaspersoft Studio or making changes directly in the .jrxml file using a text editor.
- 6. And, for our document(s), we shouldn't forget to to choose the same PDF Encoding type as the one we set for our font in step 4.
- 7. Export the font into a .jar file. Once again, Jaspersoft Studio can lend us a hand with doing this: Go to JasperSoft Studio > Fonts and this time click Export. Select the font and export it into a .jar file.
- 8. We have to create a new module to keep the .jar file. Inside our module folder we must create a subfolder "/lib/runtime" and put the exported .jar file in there.
- 9. Stop tomcat
- 10. Execute:
- 11. Restart tomcat
Changing the font in FOP Reports
Not every report in Openbravo is designed as a .jrxml report. For example, the Price List Report is generated using FOP. The approach to change the font in this kind of reports is different; we don't need to change the report definition but make use of the FOP configuration file. These are the steps we must follow:
- Get the desired font's .ttf file from your system or download it from the Internet. For example: DejaVuSans.ttf
The .fo reports used in Openbravo use the Helvetica font by default. To replace this font with the new one, we will modify the config/userconfig.xml file as explained here. So, we just add this new xml source snippet inside the <configuration> tags of the userconfig.xml file:
<fonts> <renderers> <renderer mime="application/pdf"> <fonts> <font embed-url="/home/openbravo/DejaVuSans.ttf" kerning="yes"> <font-triplet name="Helvetica" style="normal" weight="normal"/> <font-triplet name="Helvetica" style="normal" weight="bold"/> <font-triplet name="Helvetica" style="italic" weight="normal"/> <font-triplet name="Helvetica" style="italic" weight="bold"/> </font> </fonts> </renderer> </renderers>
Note that in this case we have our font placed in the path: /home/openbravo.
- Restart tomcat
After this change, all .fo reports in the application will use the DejaVuSans font instead of Helvetica.
Following screenshots show the results after successfully carrying out the steps mentioned above:
First, we have a Jasper Report, where the font of the title has been replaced with another font:
And last, we have a FOP Report with the default font replaced: