java.awt.font jar,加载字体了JAR文件,并创建AWT字体(作品)和寄存器iText的字体(不工作)...

I tried to write an applet that is able to create a PDF with an embedded font.

Everything works as long as it is not in an JAR file.

The following code part shows that I first create the AWT Font (which works fine with and without beeing stored in a JAR-file).

Then I want to register an iText (5.0.3) font. But here comes the error: access denied (java.io.FilePermission http:\host\jarfile\fonts\EXAMPLE.ttf read) java.security.AccessControlException).

private String font = "fonts/EXAMPLE.ttf";

/* iText font */

private Font pdfFont;

/* AWT font */

private java.awt.Font javaFont;

private DefaultFontMapper mapper = new DefaultFontMapper();

javaFont = java.awt.Font.createFont(java.awt.Font.TRUETYPE_FONT, getClass().getResourceAsStream(font));

FontFactory.register(getClass().getClassLoader().getResource(font).getPath(), javaFont.getFontName());

pdfFont = FontFactory.getFont(javaFont.getFontName(), BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 40);

/* Map the fonts */

BaseFontParameters params = new BaseFontParameters(font);

params.encoding = BaseFont.IDENTITY_H;

params.embedded = true;

mapper.putName(javaFont.getFontName(), params);

So I thought signing my applet would be a good idea but it had no effect. The same error message appears.

Am I doing something wrong or is this a security setting that cannot be deactivated? (without changing JRE policys)

Thank you!

Daniel

解决方案

perhaps you could try:

Font javaFont = Font.createFont( Font.TRUETYPE_FONT,new FileInputStream("fonts/EXAMPLE.ttf") );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值