Forum Bugs

Even page count

nateabbott
Final question of the day:

Is there a way through CSS to force an even page count? I.e. if a document comes to 81 pages, to automatically create an 82 page? I can't find anything in the CSS specs, but we are duplex printing, and need an even page count. We can render the PDF and check using something like pdftk and then add an extra page in the HTML if it's an odd number and re-prince-ify the document, but that's rather onerous, and we wanted to know if there's a way to automatically do this with CSS instead.

Thanks!
mikeday
At the moment there isn't, unless you add an empty block at the end of the document and apply page-break-before: left (or right?) to force an empty page at the end.
apfisterer
This doesn't seem to be working for me. My goal is the same as the original poster: if my document is one page I want two pages (blank 2nd page). If my document is two pages I want it left alone (two pages).

My markup has this div at the end:

<div class="HwEndOfDocument">
</div>

My CSS has this:

.HwEndOfDocument
{
page-break-before: left;
}


Without these if I have a one page document I get one page. If I have a two page document I get two pages.

With these if have what would have been a one page document I get two pages no matter if I put left or right. If I have a two page document I get three pages no matter if I put left or right. So it appears the page break is working, just not discerning between odd and even pages.

What am I doing wrong?

Many thanks...
mikeday
It works for me with this test document:
<html>
<head>
<style>
.HwEndOfDocument
{
    page-break-before: left;
}
</style>
</head>
<body>

<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<!-- UNCOMMENT TO GET FOUR PAGES:
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
<h1>Hello</h1>
-->

<div class="HwEndOfDocument">
</div>

</body>
</html>

I get one page of text and one blank page, so two pages total, or two pages of text and two blank pages, so four pages total. Do you get the same result?
apfisterer
Yes, I get the same behavior but I also get the following:

- if I leave the last 4 h1 elements commented out and I change the left to right I get 3 pages, the last two blank.
- if I uncomment the last 4 h1 elements and use left I get 4 total pages: the first two with content and the last two are blank (same as you)
- if I uncomment the last 4 h1 elements and use right I get 3 total pages: the first two with content and the last one is blank

This is isn't really the desired behavior I describe in my earlier post. Is that attainable?

Thanks, Mike.
mikeday
Sorry, I misread your initial post. It is possible to use page breaks to round up the total page count to an odd or even number, but not to round up if there is only one page and leave it alone if there is more than one. This would require something a bit more complex, if it is possible at all.
apfisterer
Not to beat a dead horse but in the off-chance satisfying my use case may still be possible (your statement "It is possible to use page breaks to round up the total page count to an odd or even number" makes it seem possible) please confirm if this is possible or not:

- in the case the document has an odd number of pages I would like one blank page added at the end to make it an even number of pages
- in the case the document already has an even number of pages I would like it left alone, i.e. not two blank pages at the end even though that does result in an even number of pages. So a two page document is left as a two page document, not turned into a four page document with two empty trailing pages.

Again, thanks...

Adrian.
mikeday
Okay, now I really understand this time. :)

Unfortunately though, I can't think of a way to do it. The logical suggestion would be "page-break-after: right" or something like that on the last element, to ensure that it is followed by the appropriate page. Currently though that's not what we support, specifying "left" or "right" only affects, page-break-before, and on page-break-after it is equivalent to specifying "always".
mikedfunk
Are there any plans to support page-break-after: right? I am going to use prince for books which need an even number of pages.
mikeday
As posted in the other thread, yes we will be supporting this in Prince 8.1. Turns out it already works for elements that are followed by other content, but not for the last element in the document. We will change this.
mikeday
Prince 8.1 is now available for download, and the page-break-after property has been changed so that it can leave a blank page at the end of the document to guarantee an even/odd page count.
ThePrintingSquirrel
Hi Mike,

can you give an example for how to force an even number of pages with the page-break-after property?

Thank you!
mikeday
You can do this:
:root {
    page-break-before: right
}
ThePrintingSquirrel
This doesn't work for me. I get an odd number of pages as if this CSS didn't exist.
mikeday
Oops sorry that example should read page-break-after, my mistake!
:root {
    page-break-after: right
}

Edited by mikeday

ThePrintingSquirrel
Perfect! Thank you.

And it also works with html {...} instead of :root {...}.