Jump to content
We've recently updated our Privacy Statement, available here ×

Font provided by Font Extension not working in charts or PDF export


jamesbutler

Recommended Posts

Hi all,

We are using the JasperReports engine 4.5.0, and reports designed with iReport 4.5.1. We have packaged the Arial font in an extension jar as described in the documentation; when I debug starting from the SimpleFontExtensionHelper class, I can see the font jar being read and new SimpleFontFace instances being created for each .TTF file inside.When reports which specify "Arial" as a text font (for both report text and chart labels) are generated on a server which doesn't have Arial installed (which is the case for many/most Linux server deployments) then the server-rendered Arial text doesn't work. This shows up differently for both PDF export and JFreeChart generation.When a PDF is generated, the following exception is logged:

Caused by: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'Arial' is not available to the JVM. See the Javadoc for more details.
	at net.sf.jasperreports.engine.util.JRFontUtil.checkAwtFont(JRFontUtil.java:358)

etc., 

and an empty PDF is generated. For those charts which specify Arial as a title or legend font, a fallback font is chosen from the operating system, often with very different metrics. If either Arial is installed on the OS or the correct .TTF files are dropped into the JRE's lib/fonts/ directory, both chart and PDF generation work as expected. If anyone can suggest what we can do to get the font extension working, I would be very grateful.



Post Edited by jamesbutler at 05/07/2012 21:10
Link to comment
Share on other sites

  • Replies 8
  • Created
  • Last Reply

Top Posters In This Topic

Hi,

"when I debug starting from the SimpleFontExtensionHelper class, I can see the font jar being read and new SimpleFontFace instances being created for each .TTF file inside."

Even in Linux you see that the Fonts were loaded properly? If not, maybe it is a path problem and your application isn't finding the extension, because of the differences between windows and linux.

Link to comment
Share on other sites

Also, see if the property "pdfEmbedded" is like this in your fonts.xml

 

<fontFamily name="Arial">

<normal>net/sf/jasperreports/fonts/arial/arial.ttf</normal>

<bold>net/sf/jasperreports/fonts/arial/arial.ttf</bold>

<italic>net/sf/jasperreports/fonts/arial/arial.ttf</italic>

<boldItalic>net/sf/jasperreports/arial/arial.ttf</boldItalic>

<pdfEncoding>Identity-H</pdfEncoding>

<pdfEmbedded>true</pdfEmbedded>

<exportFonts>

<export key="net.sf.jasperreports.html">'Arial', Helvetica, sans-serif</export>

<export key="net.sf.jasperreports.xhtml">'Arial', Helvetica, sans-serif</export>

</exportFonts>

</fontFamily>

Link to comment
Share on other sites

@diogopaludo: To clarify, I am both developing and deploying on Linux. I have removed the Microsoft font package from my dev machine to debug this issue (to the detriment of my web browsing experience), and can see the fonts being loaded and failing to work.

For reference, the font family definition in the jar is:

<?xml version="1.0" encoding="UTF-8"?><fontFamilies>   <fontFamily name="Arial">       <normal><![CDATA[fonts/ARIAL.TTF]]></normal>       <bold><![CDATA[fonts/ARIALBD.TTF]]></bold>       <italic><![CDATA[fonts/ARIALI.TTF]]></italic>       <boldItalic><![CDATA[fonts/ARIALBI.TTF]]></boldItalic>       <pdfEmbedded><![CDATA[true]]></pdfEmbedded>   </fontFamily></fontFamilies>

I have also tried adding the pdfEncoding and exportFonts tags, although I can't find much documentation on what the latter does:

 

<?xml version="1.0" encoding="UTF-8"?><fontFamilies>   <fontFamily name="Arial">       <normal><![CDATA[fonts/ARIAL.TTF]]></normal>       <bold><![CDATA[fonts/ARIALBD.TTF]]></bold>       <italic><![CDATA[fonts/ARIALI.TTF]]></italic>       <boldItalic><![CDATA[fonts/ARIALBI.TTF]]></boldItalic>       <pdfEncoding><![CDATA[identity-H]]></pdfEncoding>       <pdfEmbedded><![CDATA[true]]></pdfEmbedded>       <exportFonts>          <export key="net.sf.jasperreports.html">Arial, Helvetica, sans-serif</export>          <export key="net.sf.jasperreports.xhtml">Arial, Helvetica, sans-serif</export>       </exportFonts>   </fontFamily></fontFamilies>

Thanks for the response.

 



Post Edited by jamesbutler at 05/08/2012 22:31
Link to comment
Share on other sites

  • 2 months later...
  • 11 months later...

Need urgent help...!

When I am trying to export pdf file from java (Savvion BPM) then Japanese characters are not getting displayed. And I am getting below exception on server. I have add MS Mincho ttf file in jre and also exported jar using iReport. My font.xml file which is inside the msmincho.jar contains following text.

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
   <fontFamily name="MS Mincho">
       <normal><![CDATA[fonts/MSMINCHO.TTF]]></normal>
       <pdfEncoding><![CDATA[uniJIS-UCS2-HW-H]]></pdfEncoding>
       <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
   </fontFamily>
</fontFamilies>

I have added iTextasian.jar also but below excpetion is coming.

------------------------------------------

ExceptionConverter: java.io.UnsupportedEncodingException: UniJIS-UCS2-HW-H
        at java.lang.StringCoding.encode(StringCoding.java:269)
        at java.lang.String.getBytes(String.java:946)
        at com.lowagie.text.pdf.PdfEncodings.convertToBytes(Unknown Source)
        at com.lowagie.text.pdf.TrueTypeFont.<init>(Unknown Source)
        at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
        at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
        at com.lowagie.text.pdf.BaseFont.createFont(Unknown Source)
        at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:2068)
        at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:1817)
        at net.sf.jasperreports.engine.export.JRPdfExporter.getPhrase(JRPdfExporter.java:1786)
        at net.sf.jasperreports.engine.export.SimplePdfTextRenderer.getPhrase(SimplePdfTextRenderer.
java:89)
        at net.sf.jasperreports.engine.export.SimplePdfTextRenderer.render(SimplePdfTextRenderer.jav
a:99)

---------------------------------------------------------

Please help me as I am stuck up. Appreciate your immediate help.

Link to comment
Share on other sites

  • 2 years later...

I have the same problem, only on linux. On Windows it works, but I don't know if it is because Windows has the needed fonts or because my font extension do work.

I had to install the ttf-mscorefonts-installer package on Linux. It worked for the Arial font, which is included in the package, but didn't work for other fonts.

It's strange that I have to install fonts in my OS, because not having to do this is the reason to use font extensions.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...