iReport external font

匿名 (未验证) 提交于 2019-12-03 09:02:45

问题:

I am trying to use external font in PDF document. I have no problem with using it in iReport after installing it via Settings -> Fonts -> Install new font.

The problem that when I export the new font as extension and adding that jar to java project's classpath - the PDF couldn't be generated and fails with

JRFontNotFoundException: Font 'Arial Custom' is not available to the JVM exception

What I am doing wrong? Thank you

UPD#1:

jasperreports_extensions.properties

net.sf.jasperreports.extension.registry.factory.fonts=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory net.sf.jasperreports.extension.simple.font.families.ireportfamily1329192368547=fonts/fontsfamily1329192368547.xml 

fontsfamily1329192368547.xml

fonts directory includes all ttf files. I just added that jar to classpath.

回答1:

Here is my working sample.

The font definition file (I dig it from the font's jar file):

The jar file is in the application's classpath.

And here is my java code:

String defaultPDFFont = "Arial";  JRProperties.setProperty("net.sf.jasperreports.awt.ignore.missing.font", "true"); JRProperties.setProperty("net.sf.jasperreports.default.font.name", defaultPDFFont);  JasperReport jasperReport = JasperCompileManager.compileReport(reportSource); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);  JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName); 

I set the net.sf.jasperreports.awt.ignore.missing.font property to prevent the error you have (JRFontNotFoundException: Font 'Arial Custom' is not available to the JVM exception) in case the font is missing. And I set the net.sf.jasperreports.default.font.name property for determine the font that will be used in the resulting pdf file.

You can read info about this properties: net.sf.jasperreports.awt.ignore.missing.font and net.sf.jasperreports.default.font.name.

The resulting pdf file is using this font (Arial in this sample).



文章来源: iReport external font
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!