Jasper Reports: Font extension not working

16,337

Solution 1

A big thank you to @Tunaki for helping me to solve this issue.

The problem was solved by putting the jasperreports_extension.properties and the fonts folder in the root of the project like this:

enter image description here

Solution 2

Yeah, using simple xml font file worked for me. Here is fonts.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<fontFamilies>

    <fontFamily name="Arial Unicode MS">
        <normal><![CDATA[fonts/ARIALUNI.TTF]]></normal>
        <pdfEncoding>Identity-H</pdfEncoding>
        <pdfEmbedded><![CDATA[false]]></pdfEmbedded>
    </fontFamily>

</fontFamilies>

Here is src\main\resources\jasperreports_extension.properties:

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
net.sf.jasperreports.extension.simple.font.families.myfamily=fonts/fonts.xml

Here is structure:

enter image description here

In your code, nothing need to do, just print in normal case, UTF-8 will work!

Solution 3

I had similar issue where IReport designer preview able to show the font with bold but not in downloaded report from Spring boot.

I added the following maven dependency and solved my issue. https://mvnrepository.com/artifact/net.sf.jasperreports/jasperreports-fonts

Share:
16,337
simoi chigo
Author by

simoi chigo

Updated on July 18, 2022

Comments

  • simoi chigo
    simoi chigo almost 2 years

    I'm using multiple fonts in one of my reports that I export as a PDF, I'm using IREPORT to design my report.

    In the preview section the report looks good but when I export it from my web app it looks like I'm using one font for the whole report.

    I've searched this issue and I found two solutions for it:

    1. Export the font as .jar file from IREPORT and add it to my project [ Not a Clean way, Since I'm using Maven ].

    2. Use jasperreports_extension.properties [the one I'm having problem with!].

    I followed this tutorial step by step but still no result no error no nothing.

    Here is the code I'm using:

    jasperreports_extension.properties:

    net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory
    net.sf.jasperreports.extension.simple.font.families.myfamily=fonts/fonts.xml
    

    fonts.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <fontFamilies>
    
        <fontFamily name="Arial">
            <normal><![CDATA[fonts/arial.ttf]]></normal>
            <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        </fontFamily>
    
        <fontFamily name="Algerian">
            <normal><![CDATA[fonts/Algerian.ttf]]></normal>
            <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        </fontFamily>
    
        <fontFamily name="Bell Mt">
            <normal><![CDATA[fonts/bell-mt.ttf]]></normal>
            <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        </fontFamily>
    
        <fontFamily name="Savoye Std">
            <normal><![CDATA[fonts/SavoyeStd.ttf]]></normal>
            <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        </fontFamily>
    
        <fontFamily name="Cambria">
            <normal><![CDATA[fonts/Cambria.ttf]]></normal>
            <normal><![CDATA[fonts/cambriab.ttf]]></normal>
            <normal><![CDATA[fonts/cambriai.ttf]]></normal>
            <normal><![CDATA[fonts/cambriaz.ttf]]></normal>
            <pdfEmbedded><![CDATA[true]]></pdfEmbedded>
        </fontFamily>
    
    </fontFamilies>
    

    Since I'm using spring I tried this also fonts.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans:beans 
    
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
    
        xmlns:jee="http://www.springframework.org/schema/jee"
    
        xsi:schemaLocation="
    
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    
            http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.3.xsd
    
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.0.xsd">
    
        <beans:bean id="Arial" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
    
            <beans:property name="name" value="Arial"/>
            <beans:property name="normal" value="fonts/arial.ttf"/>       
            <beans:property name="pdfEncoding" value="Identity-H"/>
            <beans:property name="pdfEmbedded" value="true"/>
    
        </beans:bean>
    
        <beans:bean id="Algerian" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
    
            <beans:property name="name" value="Algerian"/>
            <beans:property name="normal" value="fonts/Algerian.ttf"/>       
            <beans:property name="pdfEncoding" value="Identity-H"/>
            <beans:property name="pdfEmbedded" value="true"/>
    
        </beans:bean>
    
        <beans:bean id="BellMt" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
    
            <beans:property name="name" value="Bell Mt"/>
            <beans:property name="normal" value="fonts/bell-mt.ttf"/>       
            <beans:property name="pdfEncoding" value="Identity-H"/>
            <beans:property name="pdfEmbedded" value="true"/>
    
        </beans:bean>
    
        <beans:bean id="SavoyeStd" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
    
            <beans:property name="name" value="Savoye Std"/>
            <beans:property name="normal" value="fonts/SavoyeStd.ttf"/>       
            <beans:property name="pdfEncoding" value="Identity-H"/>
            <beans:property name="pdfEmbedded" value="true"/>
    
        </beans:bean>
    
        <beans:bean id="Cambria" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
    
            <beans:property name="name" value="Cambria"/>
            <beans:property name="normal" value="fonts/Cambria.ttf"/>
            <beans:property name="bold" value="fonts/cambriab.ttf"/>
            <beans:property name="italic" value="fonts/cambriai.ttf"/>
            <beans:property name="boldItalic" value="fonts/cambriaz.ttf"/>       
            <beans:property name="pdfEncoding" value="Identity-H"/>
            <beans:property name="pdfEmbedded" value="true"/>
    
        </beans:bean>
    
    </beans:beans>
    

    And the font files in the font folder in the root package.

  • nobjta_9x_tq
    nobjta_9x_tq over 2 years
    also install your font on your server that deploying webapp