java 用itext-asian解决itext pdf中文不显示问题

来源:互联网 发布:华为java编程规范 编辑:程序博客网 时间:2024/05/17 02:27

引入itext-asian jar包,设置好字体后导出的pdf变成不能读取的了

解决方法:

因为我是引入com.lowagie.itext的jar包来写pdf的PdfPTable,而itext-asian是com.itextpdf包下的,所以相应的PdfPTable,PdfPCell之类的应该改成com.itextpdf包下的而不是com.lowagie.itext

jar包

<dependency>    <groupId>com.itextpdf</groupId>    <artifactId>itext-asian</artifactId>    <version>5.2.0</version></dependency><dependency>    <groupId>com.itextpdf</groupId>    <artifactId>itextpdf</artifactId>    <version>5.4.3</version></dependency>


相应代码

//中文字体BaseFont bfChinese = BaseFont.createFont( "STSongStd-Light" ,"UniGB-UCS2-H",BaseFont.NOT_EMBEDDED);Font font = new Font(bfChinese, 12,Font.NORMAL);PdfPCell cell = new PdfPCell(new Paragraph("测试",bigHoldFont));


0 0
原创粉丝点击