lilibit1985
lilibit1985

Reputation: 91

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.

Upvotes: 7

Views: 7854

Answers (3)

hungncv
hungncv

Reputation: 21

You put "Tahoma.ttf" font file in classpath, but declare "BTahoma.ttf" in fonts.xml

<normal>export/fonts/BTahoma.ttf</normal>

Let's change them to the same. I think that exception will be disappea.

Upvotes: 0

StarCrafter
StarCrafter

Reputation: 461

maybe you have to copy your jar file to your java_home/fonts directory. and if you are usinng maven project you have to package your jar file within a maven project with pom properties to add dependency to pom.xml

Upvotes: 0

Hirako
Hirako

Reputation: 359

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.

Upvotes: 4

Related Questions