我用ASP.NET + iTextSharp生成了一个pdf报告。
我在其中使用了几种字体,出于艺术原因,每种字体都应用于一个或两个单词。
所以文件很大。
我怎么能只嵌入我实际使用的字体呢?就像我们对MS Office选项所做的那样。
MS Office Word 2007如下所示:
“在文件中嵌入字体:
仅嵌入文档中使用的字符(最适合减小文件大小)
不嵌入常用系统字体“
或者我也可以接受另一种解决方案。
将整个页面平整为高分辨率图片。
如果编程方便,我实际上更喜欢这种解决方案。
谢谢。
发布于 2011-04-15 06:54:06
在创建启用了嵌入的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()成为属性。
https://stackoverflow.com/questions/5660781
复制相似问题