Forum How do I...?

Force page break before some chapters

ThePrintingSquirrel
We have an interesting challenge:

A booklet has several chapters. The default is to always start on an odd page (i.e. on the right), and I implemented that successfully with "page-break-after: right;".

But some chapters are insets and should follow their previous chapter immediately.
As each chapter is processed separately I believe I cannot use "page-break-before" (I tried, but it doesn't give me the break I want).

Are there any options for this scenario?

To restate the problem: Any chapter can be followed by an "inset" chapter which is allowed to start on the left or right page. But any "real" chapter following that inset should again always start on the right. I can programmatically determine what kind of chapter I'm currently processing, but I don't know its number of pages. My thinking was that if it's a normal chapter then insert a page break before it, but I don't know how as I believe "page-break-before" does not work on the first element in a file (I tried html, body, h1 to no avail)?

Thank you for your help.
ThePrintingSquirrel
I've now implemented the following solution:

The main logic detects if there is a new chapter starting that needs to begin on an odd page.
Only if such a case has been detected it includes the following CSS:
.chapter {
    page-break-before: left;
}
.chapter::before {
    content: " ";
    display: block;
    page-break-before: right;
}

Chapters are individual HTML pages with the class "chapter" on the <html> tag.
mikeday
Yes that will work!

Another solution would be to pass multiple HTML documents as input to Prince, this will also get correct page numbering.

When page-break-before: left/right appears at the start of the document it does not leave a blank page, it merely determines whether the first page is considered to be a left or right facing page for the purposes of duplex layout.
ThePrintingSquirrel
Thank you Mike.

The last paragraph is important information you might want to add to the documentation.
csant
It is actually mentioned in the documentation:

By putting break-before: left or right at the very beginning of the document, it will not leave a blank page, but instead will change whether the document begins on a left or right facing page.


We shall see if we can place it in a more prominent (or relevant) place to ease finding it!
ThePrintingSquirrel
Thank you, I missed that section when checking on how to use the directive.