jasperreports在linux环境和Windows环境下字体的设置

1.maven依赖

        <!--版本为6.0.3-->
        <dependency>
            <groupId>net.sf.jasperreports</groupId>
            <artifactId>jasperreports</artifactId>
            <version>6.0.3 </version>
        </dependency>

        <dependency>
            <groupId>com.itextpdf</groupId>
            <artifactId>itext-asian</artifactId>
            <version>5.2.0</version>
        </dependency>

特别之处版本为6.0.3的原因:这个版本包含itextpdf, itext-pdfa这两个;虽然也可以额外添加这两个依赖,但其它版本包含 itext包,版本为2.1.*.js系列,这个maven不会自动下载,容易出错。

2.jasperReport中字体的设置

fontName
PDF字体设置

对应的jrxml代码为:

<staticText>
    <reportElement x="0" y="0" width="60" height="43" backcolor="#E32522" uuid="572b4181-a6ab-41fc-88a3-759d44274eda"/>
    <box padding="5">
        <pen lineWidth="0.5"/>
    </box>
    <textElement textAlignment="Center" verticalAlignment="Middle">
            <font fontName="SansSerif" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"/>
    </textElement>
    <text><![CDATA[序号]]></text>
</staticText>

注意:虽然fontName可以选择宋体,华文中宋等,但强烈建议SansSerif,因为在Linux上运行容易报错。

3.jasperReport在Linux上运行的找不到字体问题

问题:net.sf.jasperreports.engine.util.JRFontNotFoundException: Font ‘宋体’ is not available to the JVM.
原因:因为你的fontName选择的是宋体,而不是SansSerif。我也试过选择宋体,或者华文中宋,并将字体文件放到classpath目录下,同时添加jasperreports.properties 文件,结果不行。最后只能是fontName=”SansSerif”————记录下这个问题,今天试了一天才解决~~

猜你喜欢

转载自blog.csdn.net/wu_0916/article/details/78395921