gpt4 book ai didi

java - 从 Web 应用程序以 PDF 格式部署 jasperreport 时字体不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:03:52 26 4
gpt4 key购买 nike

在我的网络应用程序中部署报告时,我遇到了一些字体问题。我希望在结果 pdf 中使用的字体是 Arial、Calibri 和 Century Gothic。

我遵循了指示的所有步骤here但无法让它工作。

这是我做的:

我修改了 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.dejavu=net/sf/jasperreports/fonts/fonts.xml
net.sf.jasperreports.extension.simple.font.families.arial=net/sf/jasperreports/fonts/fonts.xml
net.sf.jasperreports.extension.simple.font.families.calibri=net/sf/jasperreports/fonts/fonts.xml
net.sf.jasperreports.extension.simple.font.families.centurygothic=net/sf/jasperreports/fonts/fonts.xml

然后在 net\sf\jasperreports\fonts 我将包含四种样式(普通、粗体斜体 和粗斜体) 用于前面提到的每种字体。

此外,修改了net/sf/jasperreports/fonts 中的fonts.xml,现在看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>

<fontFamilies>

<fontFamily name="DejaVu Sans">
<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>
<!--
<locales>
<locale>en_US</locale>
<locale>de_DE</locale>
</locales>
-->
</fontFamily>

<fontFamily name="DejaVu Serif">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSerif.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-Italic.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSerif-BoldItalic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
<export key="net.sf.jasperreports.xhtml">'DejaVu Serif', 'Times New Roman', Times, serif</export>
</exportFonts>
</fontFamily>

<fontFamily name="DejaVu Sans Mono">
<normal>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono.ttf</normal>
<bold>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-Oblique.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/dejavu/DejaVuSansMono-BoldOblique.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
<export key="net.sf.jasperreports.xhtml">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
</exportFonts>
</fontFamily>

<!--
Mapping Java logical fonts, for the sake of HTML export only.
-->

<fontFamily name="SansSerif">
<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="Serif">
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Serif', 'Times New Roman', Times, serif</export>
<export key="net.sf.jasperreports.xhtml">'DejaVu Serif', 'Times New Roman', Times, serif</export>
</exportFonts>
</fontFamily>
<fontFamily name="Monospaced">
<exportFonts>
<export key="net.sf.jasperreports.html">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
<export key="net.sf.jasperreports.xhtml">'DejaVu Sans Mono', 'Courier New', Courier, monospace</export>
</exportFonts>
</fontFamily>

<fontFamily name="Arial">
<normal>net/sf/jasperreports/fonts/arial/arial.ttf</normal>
<bold>net/sf/jasperreports/fonts/arial/ArialBold.ttf</bold>
<italic>net/sf/jasperreports/fonts/arial/ArialItalic.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/arial/ArialBoldItalic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'Arial'</export>
<export key="net.sf.jasperreports.xhtml">'Arial'</export>
</exportFonts>
</fontFamily>

<fontFamily name="Calibri">
<normal>net/sf/jasperreports/fonts/calibri/calibri.ttf</normal>
<bold>net/sf/jasperreports/fonts/calibri/calibri-bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/calibri/calibri-italic.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/calibri/calibri-bold-italic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'Calibri'</export>
<export key="net.sf.jasperreports.xhtml">'Calibri'</export>
</exportFonts>
</fontFamily>

<fontFamily name="Century Gothic">
<normal>net/sf/jasperreports/fonts/centurygothic/century-gothic.ttf</normal>
<bold>net/sf/jasperreports/fonts/centurygothic/century-gothic-bold.ttf</bold>
<italic>net/sf/jasperreports/fonts/centurygothic/century-gothic-italic.ttf</italic>
<boldItalic>net/sf/jasperreports/fonts/centurygothic/century-gothic-bold-italic.ttf</boldItalic>
<pdfEncoding>Identity-H</pdfEncoding>
<pdfEmbedded>true</pdfEmbedded>
<exportFonts>
<export key="net.sf.jasperreports.html">'Century Gothic'</export>
<export key="net.sf.jasperreports.xhtml">'Century Gothic'</export>
</exportFonts>
</fontFamily>


</fontFamilies>

请注意,我刚刚添加了最后三种字体。

之后,我准备了 jar 文件并将其强制放入我的应用程序类路径中。到目前为止,我刚刚得到了使用普通 Sanserif 字体导出的报告...

我不知道我做错了什么,有什么想法吗?

谢谢!

快速说明:我使用的是 Jaspersoft Studio 社区版 (6.3.0),我的应用程序部署在 JBoss 服务器中。

最佳答案

我终于发现我的案例发生了什么,现在它正在工作。

当我在 Jaspersoft Studio Windows->Preferences->Fonts 中引入字体(.ttf 扩展名)时,我为 PDF 编码选择组合选择了错误的值。我首先选择了 CP1252(西欧 ANSI aka WinAnsi),如果您想以 PDF 格式导出报告,这是错误的,然后我选择了Identity-H(Unicode with horizo​​ntal写作) 而不是它工作正常。

然而,我仍然不明白的是:如果在我的报告中我只使用 Calibri 和 Century Gothic 字体,为什么当我去查看我的 PDF 中使用的字体时(文件-> Properties->Fonts) 我在使用的字体列表中也看到了 Helvetica?

关于java - 从 Web 应用程序以 PDF 格式部署 jasperreport 时字体不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43123323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com