Forum Bugs

Avoiding Page Breaks

brutaldigital

Problem

When creating a PDF from HTML, I would like to always avoid a page break directly after an H1 tag.

Prince Recommended Solution

To avoid a page break directly after a particular element you should apply the “page-break-after:avoid” CSS rule to the element.

My Results

I’ve have implemented this solution and attached both the HTML and PDF output. However, if you look at pages 7 and 10 of the PDF you will notice that there is a page break directly after an h1 tag.

Question

Is it possible to prevent this from happening? That is, can you force Prince to page break in these scenarios?
  1. example-pdf-generate.pdf2.3 MB
  2. example.html127.1 kB
    example HTML
mikeday
There appears to be a <span> element attempting to wrap a <p> element, this won't work as an inline element cannot contain a block element. What might be happening is it creates an empty span which stays on the same page as the heading, then the following paragraph gets pushed to the next page. Try getting rid of the unnecessary span element or push it inside the paragraph and see if that helps.
brutaldigital
Thanks, that's working now.