iTextSharp的设置字体为IElement [英] Itextsharp set font for IElement

查看:667
本文介绍了iTextSharp的设置字体为IElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 var htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmlText), styles);

                document.Open();


BaseFont Vn_Helvetica = BaseFont.CreateFont(@"C:\Windows\Fonts\arial.ttf", 
"Identity-H", BaseFont.EMBEDDED);

Font fontNormal = new Font(Vn_Helvetica, 12, Font.NORMAL);


                foreach (var t in htmlarraylist)
                {

                    document.Add((IElement)t);
                   //how set FontNormal if element is Paragraph?
                }

                    document.Close();



有人可以帮我请

Can someone help me please

推荐答案

您可以使用

FontFactory.RegisterDirectories();
Font fontNormal = new Font(FontFactory.GetFont("Arial", 12, Font.NORMAL))

您应该可以使用下面的设置上一个段落的字体:

You should be able to set the font on a paragraph using the following:

foreach (var t in htmlarraylist)
{
    if(t is Paragraph)
    {
        ((Paragraph)t).Font = fontNormal;
    }
    document.Add((IElement)t);
}

这篇关于iTextSharp的设置字体为IElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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