大胆不能在Jaspersoft Studio中使用除sans serif之外的字体

问题描述 投票:6回答:2

在Jaspersoft Studio中,我创建了一个报告,我希望以粗体显示标题。如果我使用sans serif字体,那么它正常工作。如果我使用其他字体,则在Jaspersoft Studio的预览中会显示粗体,但在Jasper服务器中运行报告时不显示。请帮忙。

jasper-reports pdf-generation jasperserver export-to-pdf
2个回答
5
投票

您需要创建一个jasper字体扩展jar并将它放在类路径中,既可以编译时(编译jrxmls)也可以运行时(运行报告时)。以下是jar(例如jasperreports-fonts-5.5.2.jar)的外观:

jasperreports_extension.properties应该包含很少的属性来初始化字体。 (我已经使用了基于弹簧的字体初始化。你可能需要在你的类路径中添加几个弹簧罐,如spring-core,spring-beans等,如果还没有的话。)

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.extensions.SpringExtensionsRegistryFactory
net.sf.jasperreports.extension.fonts.spring.beans.resource=fonts/fonts_def.xml

现在fonts.xml定义了要添加的字体。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">

   <bean id="fontBean001" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
       <property name="name" value="Tahoma"/>
       <property name="normal" value="fonts/Tahoma.ttf"/>
       <property name="bold" value="fonts/Tahoma_Bold.ttf"/>
       <property name="pdfEmbedded" value="true"/>
   </bean>

   <bean id="fontBean002" class="net.sf.jasperreports.engine.fonts.SimpleFontFamily">
        <property name="name" value="Arial"/>
        <property name="normal" value="fonts/Arial.ttf"/>
        <property name="bold" value="fonts/Arial_Bold.ttf"/>
        <property name="italic" value="fonts/Arial_Italic.ttf"/>
        <property name="boldItalic" value="fonts/Arial_Bold_Italic.ttf"/>
        <property name="pdfEmbedded" value="true"/>
    </bean>

</beans>

请注意,物业"pdfEmbedded""true"。最后为要添加到jar的字体添加.ttf文件。


1
投票

只需访问此站点,即可使用Jasper将自定义字体添加到PDF:

Custom Font with the Font Extension

有一个插图指南向您展示如何创建它。只需为您的字体下载* .ttf文件(例如:Arial.ttf。)

创建扩展并在Eclipse的帮助下将其导出为* .jar文件。

最后将* .jar添加到您的项目中。而已。

© www.soinside.com 2019 - 2024. All rights reserved.