Alex
Alex

Reputation: 9720

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

Upvotes: 5

Views: 16987

Answers (1)

Jason Allen
Jason Allen

Reputation: 813

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

Upvotes: 13

Related Questions