Custom PDF Fonts
When using a textual element inside Jaspersoft Studio, users can select the font used for it. Although this seems simple, there are a lot of problems when using the fonts. The main problem is that the available fonts are provided by the operating system and for this reason you can have:
- A font that it is available in one operating system isn't available in another. In this case, as fallback solution, the default font is used for the element.
- A font can be available in different operating systems but it could be slightly different from one to another.
In many cases this is simply unacceptable. Having a different font from the planned one probably will require more or less space for the text and this could have an impact, not only on the graphical appearance, but also on the layout of the report itself. To overcome this problem, the user can use external font files instead of the system provided fonts. In this way, the report will be independent of the operating system fonts and have the same appearance everywhere. The PDF format has its own set of fonts. And, if a document needs to use other fonts, they must be embedded inside the PDF using a Font Extension.
Download the Font
First, you must have the font you want to use. Jaspersoft Studio allows you to use a wide variety of Font types like TTF, SVG, WOFF and EOT. One of the most used formats is the TTF and there are plenty of websites that collect fonts with various licenses. For this tutorial we will use this one, named Carnivalee Freakshow Font, you can find it also as an attachment to this page. Download it and save the TTF file. If you have downloaded it from the linked website you will need to extract the contents of the zip file.
Create the Font Extension
Open Jaspersoft Studio, go to Window->Preferences. From the new dialog, expand the category Jaspersoft Studio on the left, select Font, and then press Add.
At this point you must provide a unique name for the Font Extension and the path to its extension. In this tutorial we are using a TTF, so we will provide it using the True Type field.
You can also specify a font variant for the Bold, Italic and Bold Italic styled text. If you don't provide this you will still able to use the font with one of those styles. The normal font will be manipulated to obtain the styled variant. But you can also provide a different Font for each of the variants. It is your choice. In this tutorial we will use only one Normal font.
You can also specify if this font is replaced when exported in PDF. But we will leave this empty since we want to use this Font also inside the PDF export. For this reason we should select "Embed this font in the PDF document" and a compatible encoding, like CP1251. Note that embedding the Font in the PDF export will make the resulting PDF file bigger.
Now click "Next". In the following steps you can provide additional information for other exporters and restrict the use of this font only to a subset of Locales. We don't need this so just click "Finish" to close the dialog and "Ok" to close the preferences dialog.
You can now open a report and, between the available Fonts you will find one named like your Font Extension, "MyCustomExtension" (If you can't see it try to close and reopen the report). Select it to see it used in the element. You can set the style to Bold, Italic and Bold Italic even if you didn't provide a specific font when you created the Font Extension.
Export the Font Extension
One of the problems that Font Extensions solves is to have the same font on every operative system so the appereance of the text will be the same. But using what is explained in this tutorial we should copy the TTF file on each system, and on each system recreate the Font Extension, with exactly the same name otherwise a report done in one will not find the font in the others. If we were using more TTF files for the text styles we should copy them also and configure more deeply the Extension. It's not hard, but it could take some time and repeating it many times could introduce errors, like a typo on the Extension name. To make this easier there is the possibility we can export our Font Extension as a JAR and use it in any project.
First, open the Preferences dialog and go to the Fonts to see all your Font Extensions. Select the previously created extension "MyCustomExtension" and click "Export".
At this point a save dialog will popup, define the name of the target file and save it. This JAR has all that is needed to use the extension on another system, you need only to share this single file to port your Font Extension to another machine. You can find the file generated in this way attached to this tutorial.
Publish the Font to the Server
Once you have your font.jar file drop this into your Iotellect/lib directory and restart server.
Was this page helpful?