java Jasper Reports PDF 不导出西里尔文值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34041619/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jasper Reports PDF doesn't export cyrillic values
提问by Nick Gun
I am trying to export jasper as pdf but It does not show the cyrillic values. When I export it as excel it does show and the output is fine, but when I try to export is as PDF it does not export the cyrillic values. The cyrillic values are not written in cyrillic font, they are written as cyrillic keyboard.
我正在尝试将 jasper 导出为 pdf,但它没有显示西里尔文值。当我将它导出为 excel 时,它确实显示并且输出很好,但是当我尝试导出为 PDF 时,它不会导出西里尔文值。西里尔文值不是用西里尔文字体书写的,而是用西里尔文键盘书写的。
The code I use to export is:
我用来导出的代码是:
JRExporter e = new JRPdfExporter();
e.setParameter(JRPdfExporterParameter.JASPER_PRINT, jasperPrint);
e.setParameter(JRPdfExporterParameter.OUTPUT_STREAM, outStream);
e.setParameter(JRPdfExporterParameter.OUTPUT_FILE_NAME, NAME);
I even tried to specift the parameter below:
我什至尝试指定以下参数:
e.setParameter(JRPdfExporterParameter.CHARACTER_ENCODING, "UTF-8");
but did not succeed. Any suggestions?
但没有成功。有什么建议?
回答by Petter Friberg
Jasper report uses iTextand always when a char is not rendered in pdfthis should be the checklist:
Jasper 报告使用iText并且总是当一个字符未在 pdf 中呈现时,这应该是清单:
- Is my actual
.tff
supported(OpenType) and can the font actually renderthe character. Not all fonts render all characters inUTF-8
, see How can I test if my font is rendered correctly in pdf? - Do I pass correct encodingto iText. In doubts (or in general) use the encoding
Identity-H
this is recommend for newer PDF standards and gives you the ability to mix different encoding. - Is my font embeddedso that if I share the pdf also computers not having this font can display the content?
- 我的实际
.tff
支持(OpenType)并且字体可以实际呈现字符。并非所有字体都呈现 .pdf 中的所有字符UTF-8
,请参阅如何测试我的字体是否在 pdf 中正确呈现? - 我是否将正确的编码传递给 iText。有疑问(或一般情况下)使用
Identity-H
推荐用于较新的 PDF 标准的编码,并使您能够混合不同的编码。 - 我的字体是否已嵌入,以便如果我共享 pdf,没有此字体的计算机也可以显示内容?
How can I ensure this is JasperReport?
我如何确保这是 JasperReport?
The deprecated methodwas to set attributes on the textElement
该方法已过时是在属性集textElement
<textElement>
<font pdfFontName="Helvetica" pdfEncoding="Identity-H" isPdfEmbedded="true"/>
<paragraph lineSpacing="Single"/>
</textElement>
The current non deprecated methodv 3-6, is to add Font Extensions and this is easily achieved by using tools like iReportor JasperSoft Studiothat can generate a .jar
of your font extension so that you can include it in your classpathdirectly.
当前未弃用的方法v 3-6 是添加字体扩展,这可以通过使用iReport或JasperSoft Studio等工具轻松实现,这些工具可以生成.jar
您的字体扩展,以便您可以将其直接包含在类路径中。
How to generate font extension .jar using iReport or JasperSoft Studio.
如何使用 iReport 或 JasperSoft Studio 生成字体扩展名 .jar。
EDIT:The problem of OP was 1 on checklist (.ttf font could not render), but surely he should consider both 2 and 3 using non deprecated method.
编辑:OP 的问题是清单上的 1(.ttf 字体无法呈现),但他肯定应该使用非弃用方法同时考虑 2 和 3。