0

I have a UI Panel called "pnlPerson" which produces the following HTML:

<table width="90%" style="border: 1px black solid">
    <tr>
        <td style="background-color: dodgerblue; color: white" colspan="12">GARANTİ : </td>
    </tr>
</table>

I then want to turn this HTML into a PDF using iText

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
pnlPerson.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();

Response.Write(pdfDoc);
Response.End();

It creates the PDF, but without inline CSS properties, so the PDF page is split. How can I solve that problem?

Joris Schellekens
  • 8,483
  • 2
  • 23
  • 54
Can Çalışkan
  • 274
  • 3
  • 16
  • Try adding absolute paths for the css files in the HTML you are rendering as a PDF. E.g. ... or http://localhost/myapplocation/Content/Css/my.css – Wheels73 Jan 03 '18 at 09:23
  • 1
    The `HTMLWorker` class has been deprecated for a long time. It has been designed for a specific use case and supports only very basic html. – mkl Jan 03 '18 at 09:23
  • 1
    Consider using pdfHTML. It's the modern version of HTMLWorker, and supports a much richer set of HTML5 and CSS3. – Joris Schellekens Jan 03 '18 at 09:27

0 Answers0