0

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

2 Answers 2

1

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);
0

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);
5
  • hi thanks for answer, this worked but how do i add font to element now? Commented Aug 9, 2013 at 6:27
  • add it in the html or trying providing the CSS as the second parameter for ParseToList
    – Karthik
    Commented Aug 9, 2013 at 6:31
  • tried this "<div style='font-family:" + Arial+ "'>"+htmldata+"</div>" not working Commented Aug 9, 2013 at 6:46
  • Answer updated.Refer here for more stackoverflow.com/questions/8452286/…
    – Karthik
    Commented Aug 9, 2013 at 7:18
  • Works fine for me i have tested it.add the fonts as i added and not with +
    – Karthik
    Commented Aug 9, 2013 at 9:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.