0

我在 itextsharp 中有以下代码

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

但是页面呈现为 html 源。有人有解决方案吗?其余代码没问题

4

2 回答 2

1

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

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);
于 2013-08-09T12:36:22.693 回答
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);
于 2013-08-09T06:04:29.693 回答