Itextsharp将html渲染为html源代码

时间:2013-08-09 06:01:43

标签: c# html asp.net itextsharp

我在itextsharp中有以下代码

productCell.AddElement(new Phrase(Server.HtmlDecode((this.Product.Description != null) ? this.Product.Description : ""), "Arial"));

但该页面呈现为html源代码。 有人有解决方案吗? 其余代码很好

2 个答案:

答案 0 :(得分:1)

只是为了回答字体部分,以便它可以帮助任何人,将块添加到块中并将字体应用于块

List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader(htmldata), null);
Paragraph pdesc=new Paragraph();
    for (int k = 0; k < htmlarraylist.Count; k++)
    {
        //Applies font to each chunk within para
        foreach (Chunk chunk in htmlarraylist[k].Chunks)
        {
            pdesc.Add(new Chunk(chunk.ToString(),arial));
        }
    }
    yourCellInDocument.AddElement(pdesc);

答案 1 :(得分:0)

试试这个。适合我

        FontFactory.RegisterDirectories();
        List<IElement> htmlarraylist = HTMLWorker.ParseToList(new StringReader("<html><head></head><body><div style='font-family: Cambria'>" + text + "</div></body></html>"), null);
        for (int k = 0; k < htmlarraylist.Count; k++)
        {
            cell.AddElement((IElement)htmlarraylist[k]);
        }
       Tbl.AddCell(cell);