How to do page numbering in header/footer htmls with wkhtmltopdf?

后端 未结 7 803
粉色の甜心
粉色の甜心 2020-12-07 12:37

I\'m developing an electronic invoicing system, and one of our features is generating PDFs of the invoices, and mailing them. We have multiple templates for invoices, and wi

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-07 13:17

    To show the page number and total pages you can use this javascript snippet in your footer or header code:

      var pdfInfo = {};
      var x = document.location.search.substring(1).split('&');
      for (var i in x) { var z = x[i].split('=',2); pdfInfo[z[0]] = unescape(z[1]); }
      function getPdfInfo() {
        var page = pdfInfo.page || 1;
        var pageCount = pdfInfo.topage || 1;
        document.getElementById('pdfkit_page_current').textContent = page;
        document.getElementById('pdfkit_page_count').textContent = pageCount;
      }
    

    And call getPdfInfo with page onload

    Of course pdfkit_page_current and pdfkit_page_count will be the two elements that show the numbers.

    Snippet taken from here

提交回复
热议问题