在創建啓用了嵌入功能的BaseFont
實例時,您需要致電myBaseFont.setSubset(true)
。需要注意的是與編碼 「身份-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()
成爲屬性。
你能告訴我們你用什麼代碼來創建嵌入的字體嗎?如果你使用'BaseFont.IDENTITY_H'作爲編碼,它應該爲你自動分配字體。 @ mark-storer在這裏談論字體嵌入更多一點:http://stackoverflow.com/questions/4525170/gdicharset-itextsharp/4541217#4541217 – 2011-04-14 14:11:40