java 将 JasperReport 导出为 PDF,缺少字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3672607/
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
Exporting a JasperReport to PDF, Characters Missing
提问by
I have a Java application that is generating JasperReports. It will create as many as three JasperPrints from a single report: one prints on the printer, one is serialized and saved to the database, and the third is exported to PDF using Jasper's built-in export capability.
我有一个生成 JasperReports 的 Java 应用程序。它将从单个报告创建多达三个 JasperPrint:一个在打印机上打印,一个被序列化并保存到数据库,第三个使用 Jasper 的内置导出功能导出为 PDF。
The problem is that when exporting to PDF, characters containing 8 or more bits (i.e. not 7-bit ASCII) are showing up as empty squares, meaning Acrobat Reader is not able to display that character. The print version is correct, and loading the database version and printing it shows up correctly. If I change the PDF exported version to a different format, e.g. XML, the character shows up fine in a web browser.
问题是导出为 PDF 时,包含 8 位或更多位(即不是 7 位 ASCII)的字符显示为空方块,这意味着 Acrobat Reader 无法显示该字符。打印版本正确,加载数据库版本并打印正确显示。如果我将 PDF 导出版本更改为不同的格式,例如 XML,则该字符会在 Web 浏览器中正常显示。
Based on the evidence, I believe the issue is something specific to font handling in PDFs, but I am not sure what.
根据证据,我认为该问题与 PDF 中的字体处理有关,但我不确定是什么。
The font used is Lucida Sans Typewriter, a Unicode monospaced font. The Windows "font" directory is listed in the Java classpath: without this step, PDF exporting fails miserably with zero text at all, so I know it is finding the font.
使用的字体是 Lucida Sans Typewriter,一种 Unicode 等宽字体。Windows“字体”目录列在 Java 类路径中:如果没有这一步,PDF 导出完全失败,文本为零,所以我知道它正在查找字体。
The specific characters not displayed are accented characters used in Spanish text: á
, é
, í
, ó
, and ú
. I haven't checked ?
but I am guessing that won't work too.
不显示具体字符在西班牙文本中使用重音字符:á
,é
,í
,ó
,和ú
。我没有检查过,?
但我猜这也行不通。
Any ideas what the problem is, areas of the system to check, or maybe parameters I need to send to the export process?
任何想法是什么问题,要检查的系统区域,或者我需要发送到导出过程的参数?
采纳答案by
The PDF encoding used for exporting was UTF-8, and apparently the font didn't support that properly. When I changed it to ISO-8859-1, every character showed up correctly in the PDF output.
用于导出的 PDF 编码是 UTF-8,显然字体没有正确支持。当我将其更改为 ISO-8859-1 时,每个字符都正确显示在 PDF 输出中。
回答by Se Song
I'm using Jasper Report 6, My team has spend a few days to display Khmer Unicode. I have found solution finally, and everything work as expected.
我正在使用 Jasper Report 6,我的团队花了几天时间来显示高棉 Unicode。我终于找到了解决方案,一切都按预期进行。
follow this https://community.jaspersoft.com/wiki/custom-font-font-extension
按照这个https://community.jaspersoft.com/wiki/custom-font-font-extension
after you exported, upload your jar file to lib folder and restart your jasper server.
导出后,将您的 jar 文件上传到 lib 文件夹并重新启动您的 jasper 服务器。
回答by Giorgos Dimtsas
In iReport, try setting the Pdf Embedded
property of your TextFields to true.
在 iReport 中,尝试将Pdf Embedded
TextFields的属性设置为 true。