开发者

Using a <style> definition makes a font unfindable in jasper reports pdf export?

开发者 https://www.devze.com 2023-04-09 16:16 出处:网络
I have a jar I include with my application with some fonts. If I paste around <font fontName=\"NimbusSansGlobal Light\" size=\"12\" pdfFontName=\"NimbusSansGlobal Light\" pdfEncoding=\"Identity-H\

I have a jar I include with my application with some fonts. If I paste around

<font fontName="NimbusSansGlobal Light" size="12" pdfFontName="NimbusSansGlobal Light" pdfEncoding="Identity-H" isPdfEmbedded="true"/>

into all my text elements, PDF output works fine. If I switch them all to use a style which defines the font as such:

<style name="SansFontStyle" isDefault="true" pdfFontName="NimbusSansGlobal Light" pdfEncoding="Identity-H" isPdfEmbedded="true"/>, then the font can't be found by the JRLoader when I try to generate reports. Interesting enough, if I use J开发者_如何学CRLoader within my application directly, the font is found fine.

Why would styles break PDF export?


Using Font Extensions should solve this problem.

Once you use font extensions, then you can set the font in the text element or in the style. You will not specify pdfFontName, pdfEncoding, or isPdfEmbedded in the report. That gets specified in the font extension.

Note: In a strict interpretation, this doesn't actually answer the question. I have no idea why styles work differently from directly setting the fonts. It seems like a bug, but maybe it's unexpected yet intentional for some reason we aren't thinking of. Therefore, I started to enter this as a comment rather than an answer. But it got too long.

Regardless, this should allow you to use styles as you want to. So I expect that it will solve the heart of the problem.

Font extensions are documented in the JasperReports (and iReport) samples and documentation, so it should be pretty easy to use them once you know that you ought to.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号