IText字体不是子集或嵌入 [英] IText font not subsetting or embedding

查看:381
本文介绍了IText字体不是子集或嵌入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在大型机平台上并从Windows上传了arial.ttf。我使用了以下代码的字体,但字体在Adobe中没有显示SUBSETTED或EMBEDDED。我甚至试图添加font.getBaseFont强制它嵌入。

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);    

Adob​​e doc显示以下字体信息:

Adobe doc show the following font information:

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


推荐答案

您创建 BaseFont 对象 bf ,但你没有做任何事情。人们可以期望你这样做:

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);

在这种情况下, font 会确保因为编码是 Identity-H ,所以嵌入了字体的子集,iText总是嵌入带有该编码的字体的子集。

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.

由于你没有对 bf 做任何事情,就好像这条线不存在一样。在这种情况下,我们留下:

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"); 

假设路径 arial.ttf 是正确的,并且该字体的别名是arial,您现在正在创建一个具有默认编码(Ansi)的字体,默认字体大小(12)和默认嵌入(false)。

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).

这与Adobe Reader中显示的内容一致。如果你想要嵌入字体的子集,至少需要:

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);

回答你的问题:iText没有嵌入字体的原因是你的事实没有告诉iText嵌入字体。

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.

这篇关于IText字体不是子集或嵌入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆