我的Java应用程序生成一个填写JasperReports报告的pdf文件,但是当我打开pdf文件时,它的所有字体总是" Arial",在报告中设置为&# 34; DejaVu Sans"。
当我使用JasperReports函数导出到pdf文件时,一切正常(之后我导入了DejaVu Sans的.ttf文件)。只有在我使用Java应用程序时,问题仍然存在。
这是我的一个子报告的开头。
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="sub_21" pageWidth="515" pageHeight="842" columnWidth="515" leftMargin="0" rightMargin="0" topMargin="30" bottomMargin="0" uuid="34ff3034-41c3-4268-b500-7252cbe01a14">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<parameter name="acp" class="acp.pdfengine.entities.PdfData"/>
<detail>
<band height="376" splitType="Stretch">
<textField isBlankWhenNull="true">
<reportElement positionType="Float" x="0" y="0" width="181" height="21" isRemoveLineWhenBlank="true" uuid="7b1fe94a-28dd-42d1-b6db-ee2dcc2d7020"/>
<textElement>
<font fontName="DejaVu Sans" size="12" isBold="true"/>
</textElement>
<textFieldExpression><![CDATA[$P{acp}.getPdfWords().getRESULT_title()]]></textFieldExpression>
</textField>
以下是填充报告并创建pdf的java代码:
filledReport = JasperFillManager.fillReport(report, params, dataSource);
JasperExportManager.exportReportToPdfFile(filledReport, data.getPdfInfo().getResourcesPath() + data.getPdfInfo().getFileName());
这是我的jasperreports-fonts.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="DejaVu Sans" visible="true">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSans.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-Oblique.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSans-BoldOblique.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
<export key="net.sf.jasperreports.xhtml">'DejaVu Sans', Arial, Helvetica, sans-serif</export>
</exportFonts>
</fontFamily>
<fontFamily name="Pictonic" visible="false">
<normal>
<ttf>net/sf/jasperreports/fonts/pictonic/pictonic.ttf</ttf>
<svg>net/sf/jasperreports/fonts/pictonic/pictonic.svg</svg>
<eot>net/sf/jasperreports/fonts/pictonic/pictonic.eot</eot>
<woff>net/sf/jasperreports/fonts/pictonic/pictonic.woff</woff>
</normal>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
</fontFamily>
</fontFamilies>
有没有人遇到同样的问题?
答案 0 :(得分:1)
@Erald在Jasper中查看Spring Boot with Reports的示例,在pom中有jasperreports dependecies。 https://github.com/karelp90/control_asp