原文連結
<a href="http://hintcnuie.iteye.com/blog/183690">http://hintcnuie.iteye.com/blog/183690</a>
轉載内容
iText中輸出中文,有三種方式:
1、使用iTextAsian.jar中的字型
BaseFont.createFont(“STSong-Light”, “UniGB-UCS2-H”,BaseFont.NOT_EMBEDDED);
2、使用Windows系統字型(TrueType)
BaseFont.createFont(“C:/WINDOWS/Fonts/SIMYOU.TTF”, BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
3、使用資源字型(ClassPath)
BaseFont.createFont(“/SIMYOU.TTF”, BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED);
第2、三種方式使用的字型多一些,但是需要和實際資源綁定,在實際項目中可以将一些字型庫和項目打包在一起,下面我們以iTextAsian中自帶的字型為例說明如何輸出中文:
一個完整的例子:
附錄: