Forum How do I...?

Force chapters begin on right page AND force blank left page

nico
Hello,

I am looking for a way to always ensure that chapters begin on a right page and to also ensure that the facing left page is always empty.

I tried :

div.chapter { page-break-before: right }


but it works only if the previous chapter ends on a right page. If it ends on a left page, I need to add two extra blank pages, but I couldn't find a way to do that.

Any idea ?

Nico
mikeday
How about using page-break-after as well, to ensure that the previous chapter finishes on a left or right page?
nico
I tried all the instructions below without success :

div.chapter { page-break-before: right; page-break-after: left; }
div.chapter { page-break-before: right; page-break-after: always; }
div.chapter { page-break-before: right; page-break-after: right; }

My explanation is that this instruction

div.chapter { page-break-before: right }

cancels the behavior of this one

div.chapter { page-break-after: left; }

and because the second instruction is canceled (and not added), the final result is only one page break instead of two. And thus I cannot obtain a blank page on the left in the case the previous chapter ends on a left page.

In the spec about page-break

http://www.w3.org/TR/CSS21/page.html#page-break-props

I read "Force one or two page breaks before (after)..."

So Prince should add one or two page breaks, but it adds only one.

But maybe I don't interpret the spec correctly.

Anyway, do you think about another solution ?

Regards,

Nico
mikeday
I'm not sure what's going on here, possibly Prince is not inserting the necessary number of page breaks when a page-break-before and page-break-after happen to coincide at the exact same point. We will investigate this issue.

In the meantime, here is a temporary workaround:
.chapter {
    page-break-before: right;
}

.chapter::after {
    content: " ";
    display: block;
    page-break-before: left
}
blakequarterly
How do I force two blank pages at the end of a document and have the footers be blank in both? I can force one blank page at the end with page-break-after, and then use @page:blank to get rid of the footers, but I can't work out how to force two blank pages. (My last page of text is a left page, and then I need a blank right and left to follow.)

Many thanks,
Sarah Jones
mikeday
The easiest way would be to add an element to the end of the document and put that in a named page that you can style to remove the headers/footers.
mikeday
By the way, the CSS3 Paged Media specification does state that at most one blank page should be generated by page-break-after/before properties, so the pseudo-element workaround given above appears to be the only way to do it.
blakequarterly
Many thanks for the suggestion. I'll try that.

Sarah
edwinalui
Re-opening this thread—I used the pseudo-element workaround, which has been great for starting new chapters after a chapter that ends on page right, but for new chapters following a chapter that ended on page left, this inserts 2 blank pages. Instead, I'd like the behavior to be either 0 or 1 blank page inserted, in order to start the new chapter on page right. Is there a way to do this? Thanks in advance!
mikeday
In that case, do you need the pseudo-element workaround? Maybe you could just put "page-break-before: left" on chapter elements?
ThePrintingSquirrel
I have also successfully applied the temporary workaround posted by Mike above.

But I have a problem with this: I am creating separate PDFs (one per chapter). While the workaround is fine for the merged PDF, it adds the empty page as the first page of the individual chapter PDF.

Is there a better solution available since this workaround?