Question

I've created one pdf document using itextsharp and would like to populate it with data from a html document

string htmlText = htmlcode.ToString();

var styles = new StyleSheet();
styles.LoadTagStyle(HtmlTags.TABLE, "border", "2");

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

//here I create font for text

BaseFont baseFont = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250,
                                                             BaseFont.EMBEDDED);
Font font = new Font(baseFont, 8);

//Now I add element to pdf

foreach (IElement t in htmlarraylist)
{
    document.Add((IElement)t);                        
}

//How can I add font for every element from htmlarraylist?

//for paragraph is like this

doc.Add(new Paragraph("țșăî", font));

but how set this font for IElement?

document.Close();
Was it helpful?

Solution

The IElement have a Font property you can assign you font to it

Example:

foreach (IElement t in htmlarraylist)
{
        t.Font = font;
        document.Add(t);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top