2012-10-19 104 views
0

我有一個函數,可以從pdf模板創建pdf。該模板包含6行文字。iText嵌入字體失敗

5行應以字體'Myriad Pro'。這工作正常。 其他1行(「名稱」)應該是字體'TheSerif'。我們通過合法供應商購買了這種字體。這條線似乎不起作用。該函數不會拋出錯誤,但在輸出PDF中該行不可讀。

我對兩種字體都使用相同的過程,所以我不知道爲什麼第二個不起作用。

BaseFont Myriad = null; 
    BaseFont TheSerif = null; 

    Myriad = BaseFont.CreateFont("D:\\Drukwerk\\MYRIADPRO-REGULAR.OTF", BaseFont.WINANSI, BaseFont.EMBEDDED); 
    TheSerif = BaseFont.CreateFont("D:\\Drukwerk\\TSer6C__.pfm", BaseFont.WINANSI, BaseFont.EMBEDDED); 

    pdfFormFields.SetFieldProperty("name", "textfont",TheSerif , null); 
    pdfFormFields.SetFieldProperty("Function", "textfont",Myriad, null); 
    pdfFormFields.SetFieldProperty("telephone", "textfont",Myriad, null); 
    pdfFormFields.SetFieldProperty("mobile", "textfont",Myriad, null); 
    pdfFormFields.SetFieldProperty("fax", "textfont",Myriad, null);  
    pdfFormFields.SetFieldProperty("emailadres", "textfont",Myriad, null); 

編輯: 我改變了字體創建以下

TheSerif = BaseFont.CreateFont("D:\\Drukwerk\\TSer6C__.pfm", 
           BaseFont.WINANSI, 
           BaseFont.EMBEDDED, 
           true, 
           FileToByteArray("D:\\Drukwerk\\TSer6C__.afm"), 
           FileToByteArray("D:\\Drukwerk\\TSer6C__.pfb")); 

該函數將PFB和AFM文件作爲參數。現在出現以下錯誤:'不是有效的.pfm文件'

回答

2

PFM文件是用於postscript字體的字體指標文件(Printer Font Metric)。該文件不包含任何字符繪圖命令。

PFM文件通常伴隨着包含字形圖的PFB或PFA文件,這是您應該使用的文件。

+1

我不是很熟悉itext,但是你應該嘗試使用這個重載BaseFont CreateFont(String name,String encoding,bool embedded,bool cached,byte [] ttfAfm,byte [] pfb,bool noThrow) PFM。您必須將pfb文件數據指定爲字節數組 –

+0

謝謝,我將嘗試此功能。你知道如何將pfb和ttfAfm作爲字節數組傳遞嗎? – Hazaart

+0

我找到了一個函數來獲取字節數組。我更新了我的問題。 – Hazaart