Paged.js How to count named page's total pages?

1.1k Views Asked by At

Current Issue is that I need to know the named page's total pages.

Example like this:

<div>
  <div class='page namedPage'></div>
  <div class='page namedPage'></div>
  <div class='page'></div>
  <div class='page'></div>
  <div class='page'></div>
</div>

There are 5 pages, but only the top two pages are named page and need to display page number like "Page 1 / 2", "Page 2 / 2", like below:

.namedPage {
  page: namedPage
}

@page namedPage{
 @bottom-center: {
  content: "Page" counter(page) "/" counter(something idk)
 }
}

I've looked into https://stackoverflow.com/a/49317785, but this solution doesn't work for dynamic named page content, I am not sure how many named pages it will be. Looking for a better way to walk around it, thanks in advance.

1

There are 1 best solutions below

0
On

Finally using document.querySlelctorAll(".rest-of-the-pages").lengthto get rest of the pages' length, then set Paged.js property "--pagedjs-page-count".

pagesArea.style.setProperty("--pagedjs-page-count", ${totalPages} - ${selectLength});