对itext导出PDF的一些小总结,以及ireport中生成中文PDF

也许大家和我一样,为了pdf生成时产生中文而苦恼,也许你和我一样,看到别人提供了一堆的jar,而找不到下载的地方,我也是找了好久才找到最后的大本营的,特写出来,方便你我他;)

也算给自己1个多小时的时间的一点见证吧.-_#

你只要去

http://prdownloads.sourceforge.net/itext/

就可以找到所有你想要的东西.包括itext最新版本,itext亚洲语言包

========================

官方网站的http://itext.sourceforge.net/downloads/iTextAsian.jar下不了,下面的地址可以用。
http://prdownloads.sourceforge.net/itext/iTextAsian.jar
 
 
不信?试试好的话记得顶一个呵呵!


===============顺便再补充一下
在JAVA中,用ireport是个不错的报表设计工具咯,可视化操作,但也有中文问题。典型的是加入itext后,中文显示乱码,并且导出到PDF后也乱码,解决方法经过探索后有如下方法解决:
1 在 ireportlib目录下,添加 iText 亚洲语言包(http://itext.sourceforge.net/downloads/iTextAsian.jar.),itext-1.01.jar;
2 在itext文本的属性框中,设置字体的属性为:
  • font name: SansSerif
  • PDF font name: STSong-Light;
  • PDF embedeed encoding前的勾选上
  • pdfEncoding :UniGB-UCS2-V (Chinese Simplified)
这样就可以解决了IReport中的PDF中文问题了;)

============
简单的说
在字体那里按照这种规则选择.
Chinese Simplified
STSong-Light with the encodings UniGB-UCS2-H and UniGB-UCS2-V
Chinese traditional
MHei-Medium and MSung-Light with the encodings UniCNS-UCS2-H and UniCNS-UCS2-V
Japanese
HeiseiKakuGo-W5 and HeiseiMin-W3 with the encodings UniJIS-UCS2-H,UniJIS-UCS2-V,UniJIS-UCS2-HW-H and UniJIS-UCS2-HW-V
Korean
HYGoThic-Medium and HYSMyeongJo-Medium with the encodings UniKS-UCS2-H and UniKS-UCS2-V
1、解决中文问题 2、附字体 3、动态html拼接转pdf public static void htmlCodeComeString(String linkcss,String htmlCode, String outputFile,String title) throws Exception { OutputStream os = new FileOutputStream(outputFile); ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(getConversionHtmlCode(linkcss,htmlCode,title)); ITextFontResolver fontResolver = renderer.getFontResolver(); URL fontPath = ItextUtil.class.getResource("simsun.ttc"); fontResolver.addFont(fontPath.toString(), BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); // 解决图片的相对路径问题 // renderer.getSharedContext().setBaseURL("file:/F:/teste/html/"); renderer.layout(); renderer.createPDF(os); System.out.println("======转换成功!"); os.close(); os.flush(); } public static void main(String[] args) { ItextUtil itextUtil = new ItextUtil(); String html = ""; html += ""; html += "企业信息"; html += " "; html += " "; html += " 登记日期"; html += " 2006-04-28"; html += " "; html += " "; html += " 纳税人编号"; html += " HSJIHKS002"; html += " "; html += " "; html += " 有效标志"; html += " Y"; html += " "; html += " "; html += " 社会信用代码"; html += " 916101317H"; html += " "; html += " "; html += " 评估机关代码"; html += " 盛世"; html += " "; html += " "; html += " 工商注销日期"; html += " 2006-04-28"; html += " "; html += " "; html += ""; String outputFile = "D:\\pdf\\aa.pdf"; try { itextUtil.htmlCodeComeString("",html,outputFile,""); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } System.out.println("生成结束!!!"); }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值