net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "仿宋" is not available to the JVM. See the Javadoc for more details.
net.sf.jasperreports.engine.util.JRFontNotFoundException: Font "仿宋" is not available to the JVM. See the Javadoc for more details.
at net.sf.jasperreports.engine.fonts.FontUtil.checkAwtFont(FontUtil.java:581)
原因jar启动去加载取消对应的字体
项目版本说明
jdk8
spring-cloud Hoxton.SR9
spring-boot 2.3.9.RELEASE
jasperreports 6.20.5
Jaspersoft Studio 6.20.5
在resources 新增jasperreports.properties
#忽略系统外字体,及后续引入其他字体 net.sf.jasperreports.awt.ignore.missing.font=true
新增jasperreports_extension.properties
# 字体扩展注册工厂类 net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory # 自定义的默认字体文件 net.sf.jasperreports.extension.simple.font.families.default=stsong/fonts.xml
新增 jstsong/fonts.xml
<?xml version="1.0" encoding="UTF-8"?> <fontFamilies> <!--<fontFamily name="Lobster Two">--> <!--<normal>lobstertwo/LobsterTwo-Regular.otf</normal>--> <!--<bold>lobstertwo/LobsterTwo-Bold.otf</bold>--> <!--<italic>lobstertwo/LobsterTwo-Italic.otf</italic>--> <!--<boldItalic>lobstertwo/LobsterTwo-BoldItalic.otf</boldItalic>--> <!--<pdfEncoding>Identity-H</pdfEncoding>--> <!--<pdfEmbedded>true</pdfEmbedded>--> <!--<!–--> <!--<exportFonts>--> <!--<export key="net.sf.jasperreports.html">'Lobster Two', 'Times New Roman', Times, serif</export>--> <!--</exportFonts>--> <!--–>--> <!--</fontFamily>--> <fontFamily name="华文宋体"> <normal>stsong/fonts/stsong.TTF</normal> <bold>stsong/fonts/stsong.TTF</bold> <italic>stsong/fonts/stsong.TTF</italic> <boldItalic>stsong/fonts/stsong.TTF</boldItalic> <pdfEncoding>Identity-H</pdfEncoding> <pdfEmbedded>true</pdfEmbedded> <exportFonts> <export key="net.sf.jasperreports.html">'华文宋体', Arial, Helvetica, sans-serif</export> <export key="net.sf.jasperreports.xhtml">'华文宋体', Arial, Helvetica, sans-serif</export> </exportFonts> <!--<locales> <locale>en_US</locale> <locale>de_DE</locale> </locales> --> </fontFamily> <fontFamily name="仿宋"> <normal>stsong/fonts/simfang.ttf</normal> <bold>stsong/fonts/simfang.ttf</bold> <italic>stsong/fonts/simfang.ttf</italic> <boldItalic>stsong/fonts/simfang.ttf</boldItalic> <pdfEncoding>Identity-H</pdfEncoding> <pdfEmbedded>true</pdfEmbedded> <exportFonts> <export key="net.sf.jasperreports.html">'仿宋', Arial, Helvetica, sans-serif</export> <export key="net.sf.jasperreports.xhtml">'仿宋', Arial, Helvetica, sans-serif</export> </exportFonts> </fontFamily> <fontFamily name="宋体"> <normal>stsong/fonts/simsun.ttc</normal> <bold>stsong/fonts/simsun.ttc</bold> <italic>stsong/fonts/simsun.ttc</italic> <boldItalic>stsong/fonts/simsun.ttc</boldItalic> <pdfEncoding>Identity-H</pdfEncoding> <pdfEmbedded>true</pdfEmbedded> <exportFonts> <export key="net.sf.jasperreports.html">'宋体', Arial, Helvetica, sans-serif</export> <export key="net.sf.jasperreports.xhtml">'宋体', Arial, Helvetica, sans-serif</export> </exportFonts> </fontFamily> </fontFamilies>
然后把windows上的C:\Windows\Fonts 的对应的字体复制到/resources/stsong/fonts 文件夹