As in CSS3, you can specify counters in the @page rule. Here is an example:
@page { counter-increment: page }
The above rule tells the layout engine to create a counter called "page" (it is called a page by agreement, it can be anything). This counter is incremented for each page. As with any counter, you can use the current counter value anywhere in the document.
For example, using this CSS rule:
#pageNumber { content: counter(page) }
and this HTML snippet:
<span id="pageNumber"></span>
You can use the current page number counter as content in an HTML document. You can even go further. Suppose you want to start your page number at 10. Then you can use the @page rule: the first rule to reset for the first page to 9.
@page { counter-increment: page } @page:first { counter-reset: page 9 }
The combination of both rules will reset the counter for the first page to 9. Then for each page (including the first) it will increase the counter. This results in a counter value of 10 for the first page, 11 for the second, etc.
You can also use pure css
Example:
@page { counter-increment: page; counter-reset: page 1; @top-right { content: "Page " counter(page) " of " counter(pages); } }
... in theory. In the real world, only PrinceXML supports this.
source share