1

I want use page number in thead. I use this code:

@media print {
body { margin: 0; }
thead { counter-reset: pages; }
.page-number:before { counter-increment: pages; content: " "; }
.page-number:after { counter-increment: page; }
.page-number:after { content: "Page " counter(page) " of " counter(pages); }
}

But this not working in chrome.

demo

Ashin Best
  • 21
  • 5

1 Answers1

0

This way:

<table>
  <thead>
    <tr>
      <th>
        <div class="page-number"></div>
      </th>
      ...
    </tr>
  </thead>
...
</table>
@media print {

  thead {
    counter-reset: pages;
  }

  .page-number:before {
    counter-increment: pages;
    content: "Page " counter(page) " of " counter(pages);
  }
}

Or using javascript:

 <script>
    window.onload = function() {
      var pageNumbers = document.getElementsByClassName('page-number');
      var pageCount = pageNumbers.length;
      
      for (var i = 0; i < pageCount; i++) {
        pageNumbers[i].textContent = 'Page ' + (i + 1) + ' of ' + pageCount;
      }
    };
  </script>
sylvain
  • 853
  • 1
  • 7
  • 20
  • If you test the proposed method, you will see that it shows the number 1 on all pages. I tested many of the suggested methods on the site, but all of them do not work in the latest versions of the Chrome browser. – Ashin Best Jul 04 '23 at 16:27