Itextsharp set font for IElement

Alex picture Alex · Jul 19, 2012 · Viewed 14.6k times · Source
 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

Answer

Jason Allen picture Jason Allen · Jul 19, 2012

You can use a font in iTextSharp using

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