node-html-pdf
node-html-pdf copied to clipboard
set page number in footer with logic?
there is a way to calculate and display the page number with some index ? something like this ?
options.footer = {
height: '50px',
contents: {
default: <div style="display: inline; float: right">{{page + index}}</div>
}
for me this worked : it will generate a footer like page 1 of 4
paginationOffset: 1, "footer": { "height": "10mm", "contents": { // Any page number is working. 1-based index default: ' page {{page}} of {{pages}}', // fallback value } }
Did you ever find a solution for this?
@quitequinn it's obviously very hacky but you can pass something like the following into options.footer.contents.default
to dynamically update the page number
<div id="pageNum">{{page}}</div>
<script>
const div = document.getElementById("pageNum")
div.innerText = Number(div.innerText) * 2
</script>
ahh nice, thanks.
In the example of the footer on the home page already shows how to count the pages.
this line makes it work automatically:
<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>