Forum Documentation

Alternative to @page :last

adkumar
In our older prince paid version (Prince 6.0 rev 8 beta 1) we had a css for last page i.e using @page :last, but in latest prince version we are getting unknown page class ':last' , is there an alternative to this @page :last css , cannot find anything in the documentation , can see its for first page and nth page only , but how to pass last page no. in nth page
mikeday
We don't have a :last page selector at the current time as it can be impossible to implement correctly due to infinite loops (for example changing the page margins on the last page, which makes it not the last page any more).

Do you wish to add or remove a header/footer on the last page?
adkumar
No we have a different css (changing the margin) in last page
mikeday
This requires a two-pass process of determining the last page and then running again with the :nth() selector to specify it by number. You can do this in one single to call to Prince using JavaScript.
adkumar
Can you give a example of how it can be done , tried below code:

Prince.trackBoxes = true;
Prince.registerPostLayoutFunc(function () {
var pages = PDF.pages;
if (pages.length > 0) {
var lastPage = pages[pages.length - 1];
console.log(lastPage.pageNum);

lastPage.marginTop = "2in";
}
});


added above code to test.js and tried to run via prince --script=test.js ....
mikeday
Right that's a great start! You would need to add a CSS rule like this:
var s = document.createElement("style");
document.body.appendChild(s);
s.textContent = "@page :nth("+lastPage+") { margin-top: 2in }";