JasperReports - font extensions does not work - ca

2019-08-03 17:56发布

问题:

i am trying to add Tahoma font to my report in my web app. I use font extension mechanism (via iReport I've exported extension jar and put it in my web app lib directory). My font.xml file looks like this:

<fontFamily name="Tahoma">
   <normal><![CDATA[fonts/tahoma.ttf]]></normal>
   <bold><![CDATA[fonts/tahomabd.ttf]]></bold>
   <pdfEncoding><![CDATA[Cp1250]]></pdfEncoding>
   <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
</fontFamily>

and my style:

<style name="TAHOMA_FONT" fontName="Tahoma" pdfFontName="Tahoma" />

The problem is that when I try to generate PDF the following error occurs:

Could not load the following font: pdfFontName: Tahoma pdfEncoding: Cp1250 isPdfEmbedded: true

This problem does not occur in iReports. Additionally when I change style to the following one the problem does not occur:

<style name="TAHOMA_FONT" fontName="Tahoma" pdfFontName="fonts/tahoma.ttf" pdfEncoding="Cp1250" isPdfEmbedded="true" />

When I put breakpoint in net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory class I can see that Tahoma family is being read.

My jasperreports version is 3.7.4.

Any suggestions?

回答1:

This was my problem. font.xml definition was fine but style definitions was not. It should be:

<style name="TAHOMA_FONT" fontName="Tahoma" />

pdfFontName, pdfEncoding, isPdfEmbedded attributes inside style tag are now deprecated and should not be used.