Jasper报告:字体扩展无法正常工作 [英] Jasper Reports: Font extension not working

查看:74
本文介绍了Jasper报告:字体扩展无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以PDF格式导出的一份报告中使用多种字体,在使用IREPORT设计报告.

在预览部分中,报告看起来不错,但是当我从网络应用中导出报告时,似乎整个报告都使用一种字体.

我已经搜索了这个问题,并找到了两个解决方案:

  1. 从IREPORT中将字体导出为.jar文件,并将其添加到我的项目中[不是一种干净的方法,因为我正在使用Maven].

  2. 使用 jasperreports_extension.properties [我遇到问题的那个!].

我遵循了

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.

解决方案

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:

这篇关于Jasper报告:字体扩展无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆