`
sxhyll
  • 浏览: 5640 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

使ItextPDF5最新版支持亚洲字符集(包含中文)

阅读更多

让itextpdf可以正常生成中文,需要一个jar包,最简单的做法就是去maven库下载

 

<dependency>

    <groupId>com.itextpdf</groupId>

    <artifactId>itextpdf</artifactId>

    <version>5.5.10</version>

</dependency>

 

<dependency>

    <groupId>com.itextpdf</groupId>

    <artifactId>itext-asian</artifactId>

    <version>5.2.0</version>

</dependency>

 

添加如下两个依赖即可。

 

BaseFont font = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

 

注意:在itext5之前,使用的是com.lowagie包,而之后包名改为了com.itextpdf,不要搞混了,不然会报一个错:

Font 'STSong-Light' with 'UniGB-UCS2-H' is not recognized.

 

欢迎加入iTextPDF中国区交流群:554713439

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics