如何对 pdf 中使用的字体进行子集化? (使用 iTextSharp)

发布于 2024-11-01 09:45:54 字数 323 浏览 1 评论 0原文

我使用 ASP.NET + iTextSharp 生成了一份 pdf 报告。
我在其中使用了几种类型的字体,出于艺术原因,每种字体都应用于一个或两个单词。
所以文件很大。

如何只嵌入我实际使用的字体?就像我们对 MS Office 选项所做的那样。

MS Office Word 2007 是这样的:
“在文件中嵌入字体:
仅嵌入文档中使用的字符(最适合减小文件大小)
不要嵌入常见的系统字体”

或者我也可以接受另一种解决方案。
将整个页面拼合为高分辨率图片。
如果编程方便的话,我其实更喜欢这个方案。

谢谢。

I generated a pdf report with ASP.NET + iTextSharp.
I used several types of fonts in it, each font applied to a word or 2 for art reasons.
So the file is large.

How can I only embed the fonts I actually used? Just like what we do with MS Office Options.

MS Office Word 2007 is like this:
"Embed fonts in the file:
Embed only the characters used in the document(best for reducing file size)
Do not embed common system fonts"

OR I can also accept another kind of solution.
Flatten the whole page to a high-resolution picture.
If the programming is convenient, I actually prefer this solution.

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深空失忆 2024-11-08 09:45:54

创建启用嵌入的 BaseFont 实例时,您需要调用 myBaseFont.setSubset(true)。请注意,使用编码“Identity-H”(又名 BaseFont.IDENTITY_H),这种情况会自动发生:

// find all fonts in the usual places across multiple OSs.
// This can be pretty slow if you have a large number fonts, or the fonts
// themselves are Really Big (ArialUnicodeMS: 23mb).
FontFactory.registerDirectories();

// here's one way to do it, using identity-h forces subsetting
Font myFontSubset1 = FontFactory.getFont(fontName1, BaseFont.IDENTITY_H);

// here's another, explicitly enable subsetting for the underlying BaseFont.
Font myFontSubset2 = FontFactory.getFont(fontName2, FontFactory.defaultEncoding, true);
myFontSubset2.getBaseFont().setSubset(true);

//or you can create the BaseFont yourself, with automagic subsetting
BaseFont myFontSubset3 = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H);

// or create it with some other encoding, and enable subsetting.
BaseFont myFontSubset4 = BaseFont.createFont(fontPath, BaseFont.WINANSI, true);
myFontSubset4.setSubset(true);

请注意,这都是 Java。在 C# 中,函数名称的首字母大写,setX(newX)getX() 成为属性。

When creating your BaseFont instance with embedding enabled, you need to call myBaseFont.setSubset(true). Note that with the encoding "Identity-H" (AKA BaseFont.IDENTITY_H), this happens automatically:

// find all fonts in the usual places across multiple OSs.
// This can be pretty slow if you have a large number fonts, or the fonts
// themselves are Really Big (ArialUnicodeMS: 23mb).
FontFactory.registerDirectories();

// here's one way to do it, using identity-h forces subsetting
Font myFontSubset1 = FontFactory.getFont(fontName1, BaseFont.IDENTITY_H);

// here's another, explicitly enable subsetting for the underlying BaseFont.
Font myFontSubset2 = FontFactory.getFont(fontName2, FontFactory.defaultEncoding, true);
myFontSubset2.getBaseFont().setSubset(true);

//or you can create the BaseFont yourself, with automagic subsetting
BaseFont myFontSubset3 = BaseFont.createFont(fontPath, BaseFont.IDENTITY_H);

// or create it with some other encoding, and enable subsetting.
BaseFont myFontSubset4 = BaseFont.createFont(fontPath, BaseFont.WINANSI, true);
myFontSubset4.setSubset(true);

Note that this is all Java. In C# the first letter of function names are capitalized and setX(newX) and getX() become properties.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文