Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font extensions does not work for JasperReports

I am trying to add Tahoma font to jasper report in my web app. I use font extension mechanism.

This exception was thrown: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'TahomaFont' is not available to the JVM. See the Javadoc for more details.

Here is my font.xml file:

<fontFamiles>
  <fontFamily name="TahomaFont">
    <normal>export/fonts/BTahoma.ttf</normal>
    <pdfEncoding>Identity-H</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
  </fontFamily>
<fontFamiles>

and here is my jasperreports.properties file :

net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.TahomaFont=export/fonts/fonts.xml

Also i have put Tahoma.ttf font file in my classpath. Here is the style tag in jasper report:

<style fontName="TahomaFont" name="tahoma"/>

Please let me know where i am going wrong. Thanks in advance.

like image 881
lilibit1985 Avatar asked Feb 02 '15 09:02

lilibit1985


People also ask

How do I use JasperReports font?

The best way to use a font in JasperReports Library is to use a font extension. Jaspersoft fonts can be configured in Studio and Server and displayed in the PDF view. Fonts can be referred from an URL and from the file system using the Preferences dialog window from the Jaspersoft Studio.


1 Answers

Putting the Tahoma.ttf font in your class path is not the way to go.

You are right to use font extensions, it's a good practice - but you need to package your fonts as font extension, into a jar and add that jar to your classpath.

  • In jasperReport, manage your fonts, in options, in the Font tab, select the font and click export as extension.
  • Package your jar and things should work fine without having to install the physical font on the JVM.

More information documented here.

like image 53
Hirako Avatar answered Oct 22 '22 09:10

Hirako