Reputation: 458
I am having following code in itextsharp
productCell.AddElement(new Phrase(Server.HtmlDecode((this.Product.Description != null) ? this.Product.Description : ""), "Arial"));
But the page is rendered as html source. Does anybody have solution? Rest of code is fine
Upvotes: 0
Views: 1405
Reputation: 458
Just to answer font part, so that it help anyone, take para add in chunks and apply font to chunks
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);
Upvotes: 1
Reputation: 2399
Try this. works for me
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);
Upvotes: 0