0

Below is the html content :

string headerData= "<table style='width: 100%;'><tbody><tr><td style='width: 50%; border: 0.1px solid #000; backgroundcolor:#f2f2f2; color: #000; height: 22px;font-weight:bold;text-align:right'>Territory:&nbsp;&nbsp;</td><td>USA</td></tr></tbody></table>"

Now i want to export pdf using itextsharp. in which i want to repeat header in every page so i am using "OnStartPage" event from "PdfPageEventHelper". I can write simple text (like "hello Word") or image but not able render html text.

 PdfPTable table = new PdfPTable(2);
 PdfPCell cellHeaderSection = new PdfPCell(new Phrase(headerData));
 table.AddCell(cellHeaderSection); 
 table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);

But unfortunately it showing html format text only like below image enter image description here

chirag
  • 123
  • 1
  • 10
  • You need something that can interpret the HTML. This is a huge task. You should use something that people have already written like: https://wkhtmltopdf.org/ – itsme86 Aug 14 '18 at 15:03
  • This is a duplicate of two questions. (1.) you are using an old version of iText. PDF to HTML conversion is done with the pdfHTML add-on nowadays: https://stackoverflow.com/questions/47895935 (2.) you need something that can interpret the HTML. That used to be done with XML Worker in old PDF versions: https://stackoverflow.com/questions/33394158 I'm going to close your question, but I'm not sure which of both duplicates to pick yet. – Bruno Lowagie Aug 14 '18 at 15:04
  • Also note that the documentation explictly warns that you shouldn't add content in the `OnStartPage()` method of a page event. See https://stackoverflow.com/a/24064226/1622493 I closed your question referring to the iText 5 answer, but since you're only starting with your project, you really should use iText 7 instead, because iText 5 is no longer supported. Using iText 7 is the more future-proof approach. – Bruno Lowagie Aug 14 '18 at 15:07
  • @ Bruno Lowagie : but i am using from “OnStartPage” event in “PdfPageEventHelper”. – chirag Aug 14 '18 at 15:10
  • @@Bruno Lowagie : its not duplicate .. every example showing render simple text or paragraph or image.. but no one is showing how to render Html Content.. i am looking for solution. – chirag Aug 14 '18 at 15:19

0 Answers0