我面临的问题是,JasperReports仍然无法找到Arial字体.
我创建了一个简单的Maven项目,其结构如下,并将其包含在我的主应用程序中.因此主应用程序在classpath中包含已安装的JAR:
- jasperreports_extension.properties - fonts |-> arial |-> ariali.ttf |-> arialbi.ttf |-> arialbd.ttf |-> arial.ttf |-> fonts.xml
但是在将报告导出为PDF时,我仍然会看到以下异常.
net.sf.jasperreports.engine.JRRuntimeException: Could not load the following font : pdfFontName : Arial pdfEncoding : Identity-H isPdfEmbedded : true
jasperreports_extension.properties
net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory net.sf.jasperreports.extension.simple.font.families.arial=fonts/fonts.xml
fonts.xml:
<?xml version="1.0" encoding="UTF-8"?> <fontFamilies> <fontFamily name="Arial"> <normal>fonts/arial/arial.ttf</normal> <bold>fonts/arial/arialbd.ttf</bold> <italic>fonts/arial/ariali.ttf</italic> <boldItalic>fonts/arial/arialbi.ttf</boldItalic> <pdfEncoding>Identity-H</pdfEncoding> <pdfEmbedded>true</pdfEmbedded> </fontFamily> </fontFamilies>
模板
<font fontName="Arial" size="8" pdfFontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
解决方法
问题是模板本身:在一个字体标签处< fontName>财产缺失:
不起作用:
<font size="12" isBold="true" pdfFontName="Arial"/>
工作:
<font fontName="Arial" size="12" isBold="true" pdfFontName="Arial" pdfEncoding="Identity-H" isPdfEmbedded="true"/>