Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Itextsharp set font for 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

like image 551
Alex Avatar asked Jul 19 '12 14:07

Alex


1 Answers

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);
}
like image 117
Jason Allen Avatar answered Sep 28 '22 17:09

Jason Allen