1

Having an issue when converting a HTML page to a PDF using NReco, where div's with the style 'page-break-before:always;' will not leave a page break when it's converted to a PDF.

Below is the code that actually converts the html to PDF

var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter();
var pdfBytes = htmlToPdf.GeneratePdf(htmlContent);

Response.ContentType = "Application/pdf";
Response.BinaryWrite(pdfBytes);
Response.End();

Below is a segment of HTML

</div>
<div>

      <h3 style="page-break-before:always;">
          Forsikringsbevis fortsat
      </h3>

      <!-- Second large table -->
      <div>

Below is a screenshot of the pdf without the pagebreak.

Image displaying pagebreak issue

I figure that for some reason the CSS isn't getting picked up, however other CSS is being displayed on the page, like the colouring for example.

Any ideas?

DubDub
  • 1,277
  • 1
  • 10
  • 24

1 Answers1

2

In case of wkhtmltopdf, when you specify element with 'page-break-before:always;' it should NOT be inside table or floating elements. In other words, this should be top-level element inside <body>.

In case of table, it is not possible to force page break manually inside table, but it is possible to prevent breaks inside table cells.

Vitaliy Fedorchenko
  • 8,447
  • 3
  • 37
  • 34
  • Thankyou for your assistance, I'm surprised wkhtmltopdf doesn't account for this, however I guess you can't win them all. In my case, I had a div wrapping everything, so removing it from that div fixed the problem, thankyou! – DubDub Nov 06 '18 at 09:40