Using Fonts in System with iTextSharp

后端 未结 4 807
粉色の甜心
粉色の甜心 2020-12-16 16:45

I want to use iTextSharp to write some text. I\'m using this method:

var font = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.WINANSI, BaseFont.EMBEDDED)         


        
4条回答
  •  攒了一身酷
    2020-12-16 17:06

    1st you need to register the font and then just retrieve it from the FontFactory (and don't create it every time):

    public static iTextSharp.text.Font GetTahoma()
    {
        var fontName = "Tahoma";
        if (!FontFactory.IsRegistered(fontName))
        {
             var fontPath = Environment.GetEnvironmentVariable("SystemRoot") + "\\fonts\\tahoma.ttf";
             FontFactory.Register(fontPath);
        }
        return FontFactory.GetFont(fontName, BaseFont.IDENTITY_H, BaseFont.EMBEDDED); 
    }
    

提交回复
热议问题