解决jasperreport pdf导出错误Could not load the following font问题

来源:互联网 发布:微波炉品牌选择 知乎 编辑:程序博客网 时间:2024/06/03 23:40

在使用jasperreport做报表的时候,出现以下错误,折腾了很久,网上查了很多资料,终于解决

net.sf.jasperreports.engine.JRRuntimeException:Could not load the following font :

pdfFontName   : STSong-Light
pdfEncoding   : UniGB-UCS2-H(Chinese Siplified)

isPdfEmbedded : true

导致这个问题的原因是 itext-asian.jar包经过更新,其包名已经更改为com.itextpdf.text.pdf.fonts。但是jasperreport包里查找字体文件仍是com.lowagie.text.pdf.fonts路径。

本人解决方法:

将itext-asian.jar包中所有文件拷贝出来,修改包名,并重新打包为custom-fonts.jar包。引入即可。


戏剧性的是解决完,发现一个和自己特别相似的解决方案,其中有更详细说明,补充其链接:http://blog.csdn.net/sanqima/article/details/50374151


另外设置默认字体,在jrxml中增加以下配置即可,不必每一个控件都设置

<style name="Base" isDefault="true" fontSize="10" pdfFontName="STSong-Light" pdfEncoding="UniGB-UCS2-H" isPdfEmbedded="true"> </style>


阅读全文
0 0
原创粉丝点击