jasper-reports

Font-extensions

Creating and using font extensions

Create a font extension using the IDE. See the iReport or Jaspersoft Studio documentation for details. The font extension can also be created manually.

What are font extensions?

Using a textElement you can specify a font (if not specified default font SansSerif is used)

<textElement>
    <font fontName="DejaVu Sans"/>
</textElement>

To calculate font-metric (for line breaks, alignment etc) and render the font correctly, the font needs to be mapped in the JVM (Java virtual macchine). You could install the font file directly to the JVM but this is not encourage

From the JasperReport Ultimate Guide:

We strongly encourage people to use only fonts derived from font extensions, because this is the only way to make sure that the fonts will be available to the application when the reports are executed at runtime. Using system fonts always brings the risk for the reports not to work properly when deployed on a new machine that might not have those fonts installed

Default font extension

JasperReports provide a default font-extension (see maven distribution jasperreports-fonts.jar). Adding this to classpath you can use the following fontName’s without creating your own font-extension

DejaVu Sans
DejaVu Serif
DejaVu Sans Mono

Common Issues

Issues to consider when using font’s in pdf (itext):

  • When exporting to PDF, if the text is not rendered correctly (missing parts, characters not showed, not wrapping or sized correctly), the font-extensions are likely missing.

  • Is the actual .tff supported (OpenType) and can the font actually render the character? Not all fonts render all characters in UTF-8.

  • Is the correct encoding passed to iText? In doubts (or in general) use the encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.

  • Is the font embedded so that a PDF shared across computers can display the content even if the font is not installed? If the font is not one of the 14 Standard Type 1 fonts always embed it.

Note the version of iText used by jasper report will not render all fonts (ligaturizer problem), You can test the ttf font and encoding directly see https://stackoverflow.com/questions/35127956/how-can-i-test-if-my-font-is-rendered-correctly-in-pdf


This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow