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);
Sign up to request clarification or add additional context in comments.

Comments

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 Comments

hi thanks for answer, this worked but how do i add font to element now?
add it in the html or trying providing the CSS as the second parameter for ParseToList
tried this "<div style='font-family:" + Arial+ "'>"+htmldata+"</div>" not working
Answer updated.Refer here for more stackoverflow.com/questions/8452286/…
Works fine for me i have tested it.add the fonts as i added and not with +

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.