Problem with font extension in PDF

I need to style some text in a PDF export Arial bold, italic or bold italic. I've created extensions for all three, using the corresponding Windows font files. They show up as expected in the Jaspersoft Studio Font dropdown. I then exported them to a jar. I looked in the jar file and everything looks good. The fontsfamily.xml file contains:
 
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
  <fontFamily name="Arial-Italic">
    <italic>fonts/Arial_Italic/ariali.ttf</italic>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
    <exportFonts>
    </exportFonts>
  </fontFamily>
  <fontFamily name="Arial-Bold">
    <bold>fonts/Arial_Bold/arialbd.ttf</bold>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
    <exportFonts>
    </exportFonts>
  </fontFamily>
  <fontFamily name="Arial-Bold-Italic">
    <boldItalic>fonts/Arial_Bold_Italic/arialbi.ttf</boldItalic>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
    <exportFonts>
    </exportFonts>
  </fontFamily>
</fontFamilies>
 
In my case I'm using it in a web app, so it's with the rest of  my jars in WEB-INF/lib. For a fixed text element which I want in Arial Italic, I selected "styled" in the markup dropdown, and added a <style> element to the text:
 
 <staticText>
     <reportElement style="Large" x="30" y="40" width="126" height="30" uuid="7e908695-0594-4452-9a82-471ef38d7281">
         <property name="com.jaspersoft.studio.unit.y" value="pixel"/>
     </reportElement>
     <textElement markup="styled"/>
     <text><![CDATA[<style pdfFontName="Arial-Italic" isPdfEmbedded="true">Public Security Division</style>]]></text>
 </staticText>
 
But when I try to generate the PDF in my web app, I get this exception:
 
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font: 
pdfFontName: Arial-Italic
pdfEncoding: Cp1252
isPdfEmbedded : true
    at net.sf.jasperreports.engine.export.JRPdfExporter.getFont(JRPdfExporter.java:2278)
    at net.sf.jasperreports.engine.export.JRPdfExporter.getChunk(JRPdfExporter.java:2069)
    ....
    
I'm at a loss. Any suggestions?
RTThomas's picture
258
Joined: Feb 5 2016 - 3:44pm
Last seen: 3 years 5 months ago

Thanks for the tip, but placing the font jar in tomcat/lib made no difference

RTThomas - 7 years 5 months ago

6 Answers:

Try placing the jar in apache-tomcat/lib and restarting tomcat and see if that works.

hozawa's picture
190499
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 years 3 months ago

How did you create the font extension? Using Jasper Studio, the generated fontfamily configuration file should be something like the following:

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
  <fontFamily name="testArial">
    <normal>fonts/testArial/arial.ttf</normal>
    <bold>fonts/testArial/arialbd.ttf</bold>
    <italic>fonts/testArial/ariali.ttf</italic>
    <boldItalic>fonts/testArial/arialbi.ttf</boldItalic>
    <pdfEncoding>Cp1252</pdfEncoding>
    <pdfEmbedded>true</pdfEmbedded>
    <exportFonts>
    </exportFonts>
  </fontFamily>

</fontFamilies>

tchen's picture
123022
Joined: Feb 27 2008 - 7:33am
Last seen: 3 days 9 hours ago

I just followed the instructions at http://community.jaspersoft.com/wiki/custom-font-font-extension. (I used the three separate font files fronm Windows/fonts, one for each variant. I exported them together.)

But the line

<italic>fonts/Arial_Italic/ariali.ttf</italic>

does look odd with the underscore instead of the hyphen.

I tried again using underscores rather than hyphens, - recreated the extensions, exported, changed to underscores in my jrxml, but still the same error.

RTThomas's picture
258
Joined: Feb 5 2016 - 3:44pm
Last seen: 3 years 5 months ago

Are you using Jaspersoft Studio 6.2.0. Some of the earlier versions had problem with external font generation.

hozawa's picture
190499
Joined: Apr 24 2010 - 4:31pm
Last seen: 4 years 3 months ago

Please download "testArial.jar" and use it in your report to run a test - make sure to use font extension name "testArial" in your report field.

This font jar was created in Jasper Studio version 6.1.1 and several of my users had used it as the sample to generate and deploy font extension into their JRS installation successfully.

Attachments: 
AttachmentSize
File testarial.jar1.42 MB
tchen's picture
123022
Joined: Feb 27 2008 - 7:33am
Last seen: 3 days 9 hours ago

Thanks for that jar. It works fine.

RTThomas's picture
258
Joined: Feb 5 2016 - 3:44pm
Last seen: 3 years 5 months ago
Feedback