4

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)?

damoiser
  • 6,058
  • 3
  • 40
  • 66

1 Answers1

2

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 = ""
    }
  }
}
Tachyons
  • 2,131
  • 1
  • 21
  • 35
  • thanks for your proposal, I will try it the next time I will need it! [ if before other uses confirm me the validity of your answer - I will accept it ] – damoiser Oct 08 '15 at 20:09
  • The if statement you added at the bottom (`if (vars["topage"] == vars["page"])...`) should be outside of the for loops. It only needs to be run once at the end. – David North Jun 19 '19 at 06:38