我正在使用iTextSharp生成動態PDF文檔。我有一個要求使用一個非常特定的字體,我有許可的.ttf文件。從iTextSharp中的嵌入式資源中加載BaseFont
我可以使用下面的代碼來加載和使用字體,但我更喜歡將字體文件定位爲嵌入式資源,而不是依賴磁盤上的特定位置。
string fontpath = Server.MapPath(".");
BaseFont customfont = BaseFont.CreateFont(fontpath + "myspecial.ttf", BaseFont.CP1252, BaseFont.EMBEDDED);
Font font = new Font(customfont, 12);
string s = "My expensive custom font.";
doc.Add(new Paragraph(s, font));
任何人都可以幫助我如何實現這一目標嗎?
public static BaseFont CreateFont(String name, String encoding, bool embedded, bool cached, byte[] ttfAfm, byte[] pfb)
ttfAfm
應該代表TTF:
結帳此鏈接iTextSharp的站點http://www.mikesdotnetting.com/Article/81/iTextSharp-Working-with-Fonts – MethodMan 2012-01-08 23:19:05
@DJKRAZE資源文件 - 你引用的網站中的哪個地方討論了從嵌入式資源中加載字體? – 2012-01-08 23:22:53