Frage

I followed all the examples I could find on the internet to embed an OTF font into the generated PDF but it doesn't work. I created a font extension .jar using iReport (I have also created a maven jar for fonts manually) but it doesn't work with OTF fonts. I also made sure that the jasper-fonts-extension.jar is on the classpath. I know it, because when I replace this font with some other TTF fonts, it just works.

I am running on -

Jasper Reports & iReport Version : 4.7.1
Oracle Java SDK 7
Ubuntu 12.04

The font I am trying to embed in the PDF - Myraid Pro (OTF)

My fonts.xml looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
   <fontFamily name="Myriad Pro">
   <normal><![CDATA[fonts/MyriadPro-Regular.otf]]></normal>
   <bold><![CDATA[fonts/MYRIADPRO-BOLD.OTF]]></bold>
   <italic><![CDATA[fonts/MYRIADPRO-CONDIT.OTF]]></italic>
   <boldItalic><![CDATA[fonts/MYRIADPRO-BOLDIT.OTF]]></boldItalic>
   <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
   </fontFamily>
   <fontFamily name="Myriad Pro Lite">
      <normal><![CDATA[fonts/MYRIADPRO-COND.OTF]]></normal>
      <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
   </fontFamily>
</fontFamilies>

This worked with other TTF fonts but when I switch to MyraidPro fonts, I get the following error

Exception in thread "main" java.lang.ExceptionInInitializerError
at net.sf.jasperreports.engine.fill.JRBaseFiller.<init>(JRBaseFiller.java:121)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:88)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:103)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.<init>(JRVerticalFiller.java:61)
at net.sf.jasperreports.engine.fill.JRFiller.createFiller(JRFiller.java:153)
at net.sf.jasperreports.engine.fill.JRFiller.fill(JRFiller.java:122)
at net.sf.jasperreports.engine.JasperFillManager.fill(JasperFillManager.java:464)
at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:861)
at com.qedrix.formbuilder.pojo.JsonForm.main(JsonForm.java:141)

Caused by: net.sf.jasperreports.engine.util.JRFontNotFoundException: Font 'fonts/MyriadPro-Regular.otf' is not available to the JVM.

I also followed the steps given in the following link: here

If this is something to do with the OTF fonts, I wonder why this wont work when exporting a PDF in Java while it works in iReport's preview mode?

War es hilfreich?

Lösung

I think this is a little bug in JasperReports. The entry in "fonts.xml"

<normal><ttf>fonts/OfficinaSansStd-Book.otf</ttf></normal>

throws the exception. If you RENAME your font file and change the entry to

<normal><ttf>fonts/OfficinaSansStd-Book.ttf</ttf></normal>

it works fine with me.

Andere Tipps

I believe you need to follow the following answer to get those fonts working in a PDF output. Use custom fonts when creating pdf using iReport

Also you may want to follow what file calls the app is using to find the font. I recommend strace on linux.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top