Font ‘STSongStd-Light’ with ‘UniGB-UCS2-H’ is not recognized.
使用 itextpdf 导出报表,不显示中文处理!但是处理好了又会报个错:Font ‘STSongStd-Light’ with ‘UniGB-UCS2-H’ is not recognized.
Font font = new Font(BaseFont.createFont( "STSongStd-Light" ,"UniGB-UCS2-H",BaseFont.NOT_EMBEDDED));
font.setSize(10);
PdfPTable table = new PdfPTable(2);
PdfPCell cell2 = new PdfPCell(new Phrase("中文可以不", font));
cell2.setFixedHeight(size);
table.addCell(cell2);
加上Font即可.还有一种是windows的处理方法
Font font = new Font(BaseFont.createFont("C:/Windows/Fonts/SIMYOU.TTF", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED));
也是可以处理不显示中文
报错问题处理:
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itextpdf</artifactId>
<version>5.5.5</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>
只需要将itextpdf版本改为5.5.5; itext-asian版本改为5.2.0即可
问题成功解决!
欢迎大佬们留言评论,共同学习!!!感谢!!!
===========================
原创文章,转载注明出处!