- Springboot:2.6.4
- jasperreports:6.20.0
使用Jaspersoft Studio-6.20.0 设计报表模板本地预览正常,但是导出PDF的时候不显示中文字符。
正常应该是如下显示:![image.png](https://img-blog.csdnimg.cn/img_convert/fbaa6547d4c02fcb00ea2f3b892a92cf.png#clientId=ue19af1ed-c75b-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=569&id=u8dd444ba&margin=[object Object]&name=image.png&originHeight=853&originWidth=1145&originalType=binary&ratio=1&rotation=0&showTitle=false&size=81641&status=done&style=none&taskId=u4aff4b8f-f051-4799-a58a-3948d8381c7&title=&width=763.3333333333334)
但是目前的结果是:
![image.png](https://img-blog.csdnimg.cn/img_convert/fb24798303e715870cba23218c89de7c.png#clientId=ue19af1ed-c75b-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=573&id=u989670a4&margin=[object Object]&name=image.png&originHeight=859&originWidth=1153&originalType=binary&ratio=1&rotation=0&showTitle=false&size=38333&status=done&style=none&taskId=ud6b778e3-b3bc-46ec-80dc-449f914bf12&title=&width=768.6666666666666)
-
加载本地字体并且导出jar包
后续模板设计器的字体名称 需要和 标签4 的一致。
![image.png](https://img-blog.csdnimg.cn/img_convert/23cc0be6c9f8fd64a4815053d194028b.png#clientId=ue19af1ed-c75b-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=705&id=u6f04976a&margin=[object Object]&name=image.png&originHeight=1057&originWidth=1330&originalType=binary&ratio=1&rotation=0&showTitle=false&size=170781&status=done&style=none&taskId=u23cb0b84-3d1b-4021-911b-98a1cb07a4e&title=&width=886.6666666666666)
此处的字体可以直接使用本地环境如Win11在C:WindowsFonts路径下,当然也可以通过其他网站下载,如字客网
- 模板的字体使用上述字体名称
注意xml文件中的font fontName
- jar包上传到本地maven库或者公司的私服
mvn install:install-file -Dfile=iTextAsian.jar -DgroupId=io.github.meta-ease -DartifactId=iTextAsian -Dversion=1.0.0 -Dpackaging=jar
- 应用依赖jar包正常导出含有中文的PDF
io.github.meta-ease iTextAsian 1.0.0