在系统中使用的字体与iTextSharp的 [英] Using Fonts in System with iTextSharp

查看:829
本文介绍了在系统中使用的字体与iTextSharp的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用iTextSharp的写一些文字。我用这个方法:

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



我的问题是:是否iTextSharp的支持所有的字体系统字体目录

My question is: does iTextSharp support all fonts in the system fonts directory?

说我有'mycoolfont'通过在字体选择对话框中用户选择的调用字体。我可以创建一个新的字体iTextSharp的这样?

Say I have a font called 'mycoolfont' selected by the user in the font chooser dialog. Can I create a new iTextSharp font like this?

var font = BaseFont.CreateFont("mycoolfont", BaseFont.WINANSI, BaseFont.EMBEDDED);
overContent.SetFontAndSize(font, fontSize);



更新:

我试过 VAR字体= BaseFont.CreateFont(宋体,BaseFont.WINANSI,BaseFont.EMBEDDED); ,但得到的错误宋体不被认可iTextSharp的

I tried var font = BaseFont.CreateFont("Verdana", BaseFont.WINANSI, BaseFont.EMBEDDED); but got the error "Verdana" is not recognized by itextsharp

推荐答案

1,你需要注册的字体,然后就从FontFactory检索(不要创建它每次)

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

这篇关于在系统中使用的字体与iTextSharp的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆