Pergunta

My application is MVC4 c#, I am using itextsharp to generate PDF files. To print special characters ≥, I use:

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);

When I published the application on a shared hosting server, got this error:

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

Copied the file to Content directory and tried to use:

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);

I get the following error:

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

Would appreciate your suggestions.

Foi útil?

Solução 2

I replaced:

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);

with

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);

It worked.

Outras dicas

This really is strange issue I faced . Posting my solution. I needed to register this font to FontFactory and retrieve this font from factory using GetFont

Try this

    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);

Hope this helps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top