Font configuration is very important for a proper report generation and exports. In pdf exports in particular, where it is possible to embed fonts into a document. Keep in mind that if a font is not found, a default system font is used, and this may cause a lot of problems with the layout of the report.
The font configuration itself is not very complicated, just follow these few steps:

Say, we want to register a font named FreeUniversal.
First we need to create a font configuration file fonts.xml and add it in the root of the classpath. Using this configuration, we should register all fonts that are used in the reports. It's recommended to register all font styles (normal, bold, italic and bolditalic).
The configuration file will look like this:

  <fontFamily name="FreeUniversal">
Now we have to add the font files to the classpath or pack them into a separate jar file and put the jar to the classpath. The font net/sf/dynamicreports/examples/fonts/FreeUniversal-regular.ttf means that the font file FreeUniversal-regular.ttf has to be found in package net.sf.dynamicreports.examples.fonts.

And finally, we need to create a file and register the font configuration file:
After applying the configuration above, you can use the font in this way:
StyleBuilder plainStyle =
  title(cmp.text("text - plain").setStyle(plainStyle))
If you want to set the font FreeUniversal as a deafult font, create a dynamicreports-defaults.xml file and set the default font name:
  <!-- DEFAULT FONT -->
  <font fontName="FreeUniversal" fontSize="10"/>
If you don't set the style in a column or any other text component, the default font is used
  title(cmp.text("text - default font"))
You can check if the configuration is working properly by exporting the report into pdf. Open the pdf document and look at the document properties and select fonts, there should be a list of all embedded FreeUniversal fonts.
For more information about font configuration visit the following site:
Font extensions

Tags: style

Latest News

  • Thu
    Changes in version 5.1.0 upgrade to JasperReports 6.5.1 removed xhtml and excelapi exporter removed thread safety...
  • Fri
    Changes in version 5.0.0 upgrade to JasperReports 6.4.0 upgrade to Java 1.7, DynamicReports is no longer compatibl...
  • Thu
    Changes in version 4.1.1 upgrade to JasperReports 6.2.2 added new types of component stretch type minor bug fixes...