简体   繁体   English

jasper report多语言 - 在spring boot中生成pdf时无法显示字体

[英]jasper report Multi language- cannot display font while generating pdf in spring boot

I'm generating a multi-language report using JasperReports in Java. 我正在使用Java中的JasperReports生成一个多语言报告。

When I generate pdf, few languages do not display properly. 当我生成pdf时,很少有语言无法正常显示。

在此输入图像描述

Whereas, When I generate Excel, The report is generated properly with the correct language. 然而,当我生成Excel时,报告是使用正确的语言正确生成的。

在此输入图像描述

searching on the internet I found pdf font is not supported. 在网上搜索我发现不支持pdf字体。

here my code set to font: 这里我的代码设置为font:

 Style rowStyle = new Style();
 Font font = new Font(FONT_SIZE_SMALL, "Noto Sans", false, false, false);
 font.setPdfFontName("Noto Sans");
 font.setPdfFontEncoding(Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing);
 font.setPdfFontEmbedded(false);
 rowStyle.setFont(font);

any idea how to solve? 任何想法如何解决?

Have you tried setting DEBUG jasper reports logging to check which font is getting used when the PDF is rendered? 您是否尝试过设置DEBUG jasper报告以检查呈现PDF时使用的字体? (example log4j setup below) (示例下面的log4j设置)

<category name="net.sf.jasperreports">
    <priority value="DEBUG" />
</category>

For example you should see DEBUG log of a font being loaded by jasper: 例如,您应该看到由jasper加载的字体的DEBUG日志:

DEBUG SimpleFontFace:177 - Loading font fonts/ARIALUNI.TTF

And if you are using jasper font extension (described below), you should see something like: 如果你使用jasper字体扩展(如下所述),你应该看到类似的东西:

 DEBUG FontExtensionsRegistry:88 - Loading font extensions from net/sf/jasperreports/fonts/jasperreports-fonts.xml

Are you including the font in the classpath? 你是否在类路径中包含了字体? I have successfully used a custom built jar similar to what is described in this post in the docs: https://community.jaspersoft.com/wiki/adding-fonts-embedding-pdf 我已经成功使用了一个自定义的jar,类似于本文中文档中描述的内容: https//community.jaspersoft.com/wiki/adding-fonts-embedding-pdf

I would also try setPdfFontEmbedded(true). 我也会尝试setPdfFontEmbedded(true)。 In the generated PDF you can determine if the font is included in the report if you open the PDF in Adobe Acrobat Reader, and see if it is listed under File -> Properties... -> Fonts tab (see screenshot). 在生成的PDF中,如果在Adobe Acrobat Reader中打开PDF,您可以确定该字体是否包含在报告中,并查看它是否列在文件 - >属性... - >字体选项卡下(参见屏幕截图)。 It should have (Embedded) or (Embedded subset) next to the font name. 它应该在字体名称旁边有(嵌入式)或(嵌入式子集)。 在此输入图像描述

Edit 编辑

Above steps can help debug issues like this. 以上步骤可以帮助调试这样的问题。 It turns out that the "Noto Sans" font doesn't support Indian characters, using "Arial Unicode MS" works though. 事实证明,“Noto Sans”字体不支持印度字符,但使用“Arial Unicode MS”可以正常工作。

In Docs , you can see how many languages are supported. 文档中 ,您可以看到支持多少种语言。

--Use below code 

 `Style rowStyle = new Style();
 Font font = new Font(FONT_SIZE_SMALL, "Arial Unicode MS", false, false, false);
 font.setPdfFontName("Arial Unicode MS");
 font.setPdfFontEncoding(Font.PDF_ENCODING_Identity_H_Unicode_with_horizontal_writing);
 font.setPdfFontEmbedded(false);
 rowStyle.setFont(font);`

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM