Web项目集成Jasperreport出现错误“Font '宋体' is not available to the JVM. See the Javadoc for more details. ”,提示找不到宋体。
参考了一些资料后,是这样解决的:
1.解压Jasperreport项目进入目录\demo\fonts\net\sf\jasperreports\fonts\dejavu
2.将C:\WINDOWS\Fonts目录中的宋体字体文件,拷贝到上述目录中,并修改后缀为simsun.ttf
3.修改\demo\fonts\net\sf\jasperreports\fonts目录中的fonts.xml,追究fontFamily元素,并配置宋体信息:
<fontFamily name="宋体"> <normal>net/sf/jasperreports/fonts/dejavu/simsun.ttf</normal> <bold>net/sf/jasperreports/fonts/dejavu/simsun.ttf</bold> <italic>net/sf/jasperreports/fonts/dejavu/simsun.ttf</italic> <boldItalic>net/sf/jasperreports/fonts/dejavu/simsun.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>
4.demo\fonts目录下的字体项目是通过maven来进行管理的,由于自定义了项目所以需要修改pom.xml文件。我只修改了groupId,然后在Web项目中,添加自定义的依赖,最后把fonts项目编译后的Jar包放到了私服Nexus中
5.最后,在Web项目的根目录增加配置文件jasperreports.properties,内容:
net.sf.jasperreports.awt.ignore.missing.font=true net.sf.jasperreports.extension.registry.factory.simple.font.families=net.sf.jasperreports.engine.fonts.SimpleFontExtensionsRegistryFactory net.sf.jasperreports.extension.simple.font.families.dejavu=net/sf/jasperreports/fonts/fonts.xml
6.修改Web项目的pom.xml文件,增加对fonts项目包的依赖
参考内容:
http://vase.iteye.com/blog/762507