문제

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();
도움이 되었습니까?

해결책

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);
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top