Download the fonts from the JAR file and create an AWT font (works) and register the iText font (does not work)

I tried to write an applet that can create a PDF with an embedded font. Everything works as long as it is not in the JAR file.

The next part of the code shows that I first create an AWT font (which works fine with and does not write to the JAR file). Then I want to register the iText font (5.0.3). But here an error occurs: 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 didn’t affect. The same error message will appear. Am I doing something wrong or is it a security setting that cannot be disabled? (without changing the rules of the JRE)

Thanks! Daniel

0
source share
1 answer

maybe you could try:

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

0
source

All Articles