IText font not subsetting or embedding

本秂侑毒 提交于 2020-01-06 19:37:30

问题


I am on the mainframe platform and uploaded the arial.ttf from Windows.
I used the following code for the font, but the font does not show SUBSETTED or EMBEDDED in Adobe.
I even tried to add font.getBaseFont to force it to embed.

Any reason why it would not embed or subset?

String font1 = "arial.ttf";                                                
FontFactory.register(font1,"myfont");                                      
BaseFont bf = BaseFont.createFont(font1, BaseFont.IDENTITY_H, true);       
Font font =  FontFactory.getFont("arial");   

font.getBaseFont().setSubset(true);    

Adobe doc show the following font information:

Type truetype
Encoding Ansi
Actual Font: ArialMT
Actual Font type: TrueType

回答1:


You create a BaseFont object bf, but you aren't doing anything with it. One would expect that you do this:

BaseFont bf = BaseFont.createFont(pathToFont, BaseFont.IDENTITY_H, true);
Font font = new Font(bf, 12);

In this case, font would make sure that a subset of the font is embedded because the encoding is Identity-H and iText always embeds a subset of a font with that encoding.

As you aren't doing anything with bf, it is as if the line isn't present. In that case, we are left with:

String font1 = "arial.ttf";                                                
FontFactory.register(font1,"myfont");    
Font font =  FontFactory.getFont("arial"); 

Assuming that the path to arial.ttf is correct, and that the alias of that font is "arial", you are now creating a font with the default encoding (Ansi), the default font size (12) and the default embedding (false).

That is in line with what is shown in Adobe Reader. If you want a subset of the font to be embedded, you need at least:

Font font =  FontFactory.getFont("arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

In answer to your question: the reason why the font is not embedded by iText is the fact that you are not telling iText to embed the font.



来源:https://stackoverflow.com/questions/27916142/itext-font-not-subsetting-or-embedding

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