Reputation: 6238
I render a pdf that doesn't have a fixed height. I would like to append a footer at the bottom of the last page only, I have tried to play with css but it's still showing on the footer of the first page.
Any ideas?
At this moment I have a css like this
body {
# tried with height: 100% too
height: 269mm; # a standard A4 height
}
div.footer {
position: absolute; # tried with fixed too
bottom: 0px;
height: 200px;
}
I think that the best solution is working with javascript and checking when the last page is coming, but how can I do?
Another note, seems that having:
body { height: (nr_pages * 269)mm }
is a working solution (maybe not so nice). How can I retrieve the total number of the pages (inside the view)?
Upvotes: 4
Views: 2432
Reputation: 2171
You can find last page by checking whether page attribute and topage attribute is same , in js you can use following snippet in page footer layout
function subst() {
var vars = {};
var x = document.location.search.substring(1).split('&');
for (var i in x) {
var z = x[i].split('=', 2);
vars[z[0]] = unescape(z[1]);
}
var x = ['frompage', 'topage', 'page', 'webpage', 'section', 'subsection', 'subsubsection'];
for (var i in x) {
var y = document.getElementsByClassName(x[i]);
for (var j = 0; j < y.length; ++j) y[j].textContent = vars[x[i]];
if (vars["topage"] == vars["page"]) {} else {
document.getElementById("pdf-footer").innerHTML = ""
}
}
}
Upvotes: 2