iReport 外部字体
我正在尝试在 PDF 文档中使用外部字体。通过设置 -> 安装后,我在 iReport 中使用它没有问题。字体->安装新字体。
当我将新字体导出为扩展并将该 jar 添加到 java 项目的类路径时出现的问题 - 无法生成 PDF 并且失败并出现
JRFontNotFoundException: Font 'Arial Custom' is not available for the JVM 异常
我做错了什么? 谢谢
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
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Arial Custom">
<normal><![CDATA[fonts/arial.ttf]]></normal>
<bold><![CDATA[fonts/arialbd.ttf]]></bold>
<italic><![CDATA[fonts/ariali.ttf]]></italic>
<boldItalic><![CDATA[fonts/arialbi.ttf]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<locales>
<locale><![CDATA[en_US]]></locale>
</locales>
</fontFamily>
</fontFamilies>
字体目录包含所有 ttf 文件。我刚刚将该 jar 添加到类路径中。
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
<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
<fontFamily name="Arial Custom">
<normal><![CDATA[fonts/arial.ttf]]></normal>
<bold><![CDATA[fonts/arialbd.ttf]]></bold>
<italic><![CDATA[fonts/ariali.ttf]]></italic>
<boldItalic><![CDATA[fonts/arialbi.ttf]]></boldItalic>
<pdfEncoding><![CDATA[Identity-H]]></pdfEncoding>
<pdfEmbedded><![CDATA[true]]></pdfEmbedded>
<locales>
<locale><![CDATA[en_US]]></locale>
</locales>
</fontFamily>
</fontFamilies>
fonts directory includes all ttf files. I just added that jar to classpath.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我的工作样本。
字体定义文件(我从字体的 jar 文件中挖掘它):
jar 文件位于应用程序的类路径中。
这是我的 java 代码:
我设置了
net.sf.jasperreports.awt.ignore.missing.font
属性以防止出现错误有(JRFontNotFoundException:字体“Arial Custom”不可用于 JVM 异常
),以防字体丢失。我设置了net.sf.jasperreports.default.font.name
属性来确定将在生成的 pdf 文件中使用的字体。您可以阅读有关此属性的信息: net .sf.jasperreports.awt.ignore.missing.font 和 net.sf.jasperreports.default.font.name。
生成的 pdf 文件使用此字体(本示例中为
Arial
)。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:
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 thenet.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).