用itext生成PDF报错,加上try catch捕获到异常是 BaseFont bFont = BaseFont.createFont("STSong-Light1", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);

这行代码抛出的,上网查了之后发现时itext和itextasian jar包的版本不匹配致所致, itext从5.x版本开始,改名为itextpdf, itextasian 5.2.0以下版本包名未更新,

换了5.2.0这个包之后问题就解决了, 推荐使用itextasian 5.2.0 以上版本

PS: maven引用jar包小技巧 如 itextasian

1. 百度输入: itextasian mvn

2. 点第一个进去后出现jar的版本页面,找到要引用的jar

3. xml就是要引用的,复制到pom就行了

<!-- https://mvnrepository.com/artifact/com.itextpdf/itext-asian -->
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>itext-asian</artifactId>
<version>5.2.0</version>
</dependency>

用itext生成PDF报错:Font &#39;STSong-Light1&#39; with &#39;UniGB-UCS2-H&#39; is not recognized.-LMLPHP

用itext生成PDF报错:Font &#39;STSong-Light1&#39; with &#39;UniGB-UCS2-H&#39; is not recognized.-LMLPHP

用itext生成PDF报错:Font &#39;STSong-Light1&#39; with &#39;UniGB-UCS2-H&#39; is not recognized.-LMLPHP

参考别人的文章地址:

https://blog.csdn.net/bisal/article/details/48021867

05-06 18:34