2014-03-29 37 views
0

我的應用程序是MVC4 c#,我使用itextsharp生成PDF文件。要打印特殊字符≥,我使用:itextsharp ARIALUNI.TTF複製託管服務器

string ARIALUNI_TFF = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIALUNI.TTF"); 
var bf = BaseFont.CreateFont(ARIALUNI_TFF, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); 
var f = new Font(bf, 10, Font.NORMAL); 

當我發佈一個共享的主機服務器上的應用程序,得到這個錯誤:

C:\Windows\Fonts\ARIALUNI.TTF not found as file or resource. 

文件複製到內容目錄,並試圖用:

string ARIALUNI_TFF1 = System.Web.HttpContext.Current.Server.MapPath("~/Content/ARIALUNI.TFF"); 
// FontFactory.Register(ARIALUNI_TFF1); 
var bf1 = BaseFont.CreateFont(ARIALUNI_TFF1, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); 
var f1 = new Font(bf1, 10, Font.NORMAL); 

我得到以下錯誤:

ARIALUNI.TFF' with 'Identity-H' is not recognized. 

希望你的建議。

回答

0

我代替:

string fontpath = System.Web.HttpContext.Current.Server.MapPath("~/Content/ARIALUNI.TFF");I replaced: 
    var bf = BaseFont.CreateFont(fontpath, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); 
    var f = new Font(bf, 10, Font.NORMAL); 

string fontpath = System.Web.HttpContext.Current.Server.MapPath("~/Content/"); 
BaseFont bf = BaseFont.CreateFont(fontpath + "ARIALUNI.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); 
Font f = new Font(bf, 10, Font.NORMAL); 

它工作。

+0

使用此答案我得到NullReferenceException。你能幫我解決嗎? –

0

這真是我遇到的奇怪問題。發佈我的解決方案。我需要爲這種字體的註冊FontFactory,並使用GetFont

檢索工廠這種字體試試這個

string path = System.Web.HttpContext.Current.Server.MapPath("~/Content/ArialUni.TFF"); 
    iTextSharp.text.Font fnt = new iTextSharp.text.Font(); 
    FontFactory.Register(path, "CustomAriel"); 
    fnt = FontFactory.GetFont("CustomAriel", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10,Font.NORMAL); 

希望這有助於

+0

非常感謝,工作。 – hncl

+0

我沒有收到錯誤,但≥沒有打印。 – hncl

+0

你能告訴你如何使用字體嗎? –