iReport 外部字体

发布于 2025-01-05 03:00:08 字数 1399 浏览 5 评论 0原文

我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七度光 2025-01-12 03:00:08

这是我的工作样本。

字体定义文件(我从字体的 jar 文件中挖掘它):

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
   <fontFamily name="Arial">
       <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[false]]></pdfEmbedded>
   </fontFamily>
</fontFamilies>

jar 文件位于应用程序的类路径中。

这是我的 java 代码:

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);

我设置了 net.sf.jasperreports.awt.ignore.missing.font 属性以防止出现错误有(JRFontNotFoundException:字体“Arial Custom”不可用于 JVM 异常),以防字体丢失。我设置了 net.sf.jasperreports.default.font.name 属性来确定将在生成的 pdf 文件中使用的字体。

您可以阅读有关此属性的信息: net .sf.jasperreports.awt.ignore.missing.fontnet.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):

<?xml version="1.0" encoding="UTF-8"?>
<fontFamilies>
   <fontFamily name="Arial">
       <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[false]]></pdfEmbedded>
   </fontFamily>
</fontFamilies>

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文