Font extensions does not work for JasperReports

2019-04-26 05:48发布

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.

2条回答
劳资没心,怎么记你
2楼-- · 2019-04-26 06:39

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.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-04-26 06:45

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

查看更多
登录 后发表回答