Itextsharp将html呈现为html源
本文关键字:html Itextsharp | 更新日期: 2023-09-27 18:26:53
我在itextsharp 中有以下代码
productCell.AddElement(new Phrase(Server.HtmlDecode((this.Product.Description != null) ? this.Product.Description : ""), "Arial"));
但是页面被呈现为html源。有人有解决方案吗?代码的其余部分很好
只是为了回答字体部分,这样它就可以帮助任何人,将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);
试试这个。适用于我
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);