Why doesn't jasper report throw a JRFontNotFoundException if font for PDF is missing?

会有一股神秘感。 提交于 2019-12-01 19:39:27

Your are setting pdfFontName not fontName

pdfFontName was an old way, now deprecated to indicate what font the itext library should use, jasper-reports will not throw JRFontNotFoundException if the font is missing, instead itext will throw an exception that is caught and relaunched as a JRRuntimeException.

In itext Helvetica is included as afm file, hence itext will not throw any exception if this is used, however this does not guarantee that your text is rendered correctly if you are indicating another font (in your case not indicating = default font) in jasper-reports. In fact this is a mess and both pdfFontName and pfdEncoding was deprecated.

Is there any way to abort generation of PDF if the font in attribute pdfFontName is not installed?

Don't use pdfFontName, but if you insist (for the sake of the question) then also set fontName="Helvetica", setting the jasper-reports font will raise a JRFontNotFoundException if not found.

The correct way is to only set the fontName and then provide font-extensions, in the font-extension you include the actual ttf, indicate the encoding and if it should be embedded.

BTW: I would use encoding Identity-H this is recommend for newer PDF standards and gives you the ability to mix different encoding.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!