'Django: "Page undefined of undefined" in the pdf using the wkhtmltopdf library

i have used the wkhtml2pdf library, I want to set the numbering of page on my pdf But i didn't reach my goal yet, it always show me "Page undefined of undefined",

Here is the code i have go to tag head and make this properties for the div contain the number of pages:

<style>
    div.footer {
          display: block; text-align: center;
          position: running(footer);
    @page { 
          @bottom-center { content: element(footer) }
           }
    }
</style>

then in the body, I have go and add the div with javascript code:

  <body style="border:0; margin: 0; min-height: 1123px">
    <div id="div-body">
     #code
    </div>
    <div class='footer'>
      Page <span id='page'></span> of 
      <span id='topage'></span>   
      <script> 
        var vars={};
        var x=window.location.search.substring(1).split('&');
        for (var i in x) {
          var z=x[i].split('=',2);
          vars[z[0]] = unescape(z[1]);
        }
        document.getElementById('page').innerHTML = vars.page; 
        document.getElementById('topage').innerHTML = vars.topage; 
      </script> 
  </div>
</body>  

How i can resolve that, thanks in advance.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source