将JasperReport导出为PDF,缺少字符 [英] Exporting a JasperReport to PDF, Characters Missing

查看:176
本文介绍了将JasperReport导出为PDF,缺少字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成JasperReports的Java应用程序。它将从一个报告中创建多达三个JasperPrints:一个在打印机上打印,一个序列化并保存到数据库,第三个使用Jasper的内置导出功能导出为PDF。

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.

问题是当导出为PDF时,包含8位或更多位(即非7位ASCII)的字符显示为空方块,这意味着Acrobat Reader无法显示该字符。打印版本是正确的,加载数据库版本并打印它显示正确。如果我将PDF导出版本更改为其他格式,例如XML,这个角色在网络浏览器中显示得很好。

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中字体处理特有的,但我不确定什么。

Based on the evidence, I believe the issue is something specific to font handling in PDFs, but I am not sure what.

使用的字体是Lucida Sans Typewriter,一种Unicode等宽字体。 Windowsfont目录列在Java类路径中:如果不执行此步骤,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.

未显示的特定字符是西班牙文中使用的重音字符:áé íóú。我没有检查ñ但我猜这也行不通。

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?

推荐答案

使用的PDF编码导出是UTF-8,显然字体不能正确支持。当我将其更改为ISO-8859-1时,每个字符都在PDF输出中正确显示。

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.

这篇关于将JasperReport导出为PDF,缺少字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆