'iText 7 Display a html string variable inside a pdfpcell
I am using iText7 to create a PDF in C#. I want to parse a string variable that has HTMLand inline style tags and place it into a PdfPCell, with the styling in effect. I'm building a PDF to display user comments in a PdfPTable. I am able to display them but some of the style tags are ignored. Here's an example of one of the tags that are in the comment variable.
<strong style="background-color: rgb(255, 255, 0);">
The strong works, but the style tag is completely ignored. I want the text to be highlighted.
Here's part of the code I'm using now...
foreach (var comment in comments.UserComments)
{
List<IElement> parsedComment = HTMLWorker.ParseToList(new StringReader(comment.Comment), null);
foreach (var element in parsedComment)
{
cell.AddElement(element);
cell = new PdfPCell(cell)
{ PaddingBottom = 5 };
}
commentsTable.AddCell(cell);
}
comment.Comment is the string variable parameter that contains the HTML tags.
And this is where I'm trying to parse, or convert, the HTML string to add to the cell...
List<IElement> parsedComment = HTMLWorker.ParseToList(new StringReader(comment.Comment), null);
Then I tried rewriting it like below but am getting a conversion error on cell.AddElement(element);
IList<iText.Layout.Element.IElement> parsedComment = HtmlConverter.ConvertToElements(comment.Comment);
foreach (var element in parsedComment)
{
cell.AddElement(element);
cell = new PdfPCell(cell)
{ PaddingBottom = 5 };
}
commentsTable.AddCell(cell);
Looking for suggestions on how to accomplish this.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
