node-html-pdf icon indicating copy to clipboard operation
node-html-pdf copied to clipboard

set page number in footer with logic?

Open yardenweiss opened this issue 4 years ago • 5 comments

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> }

yardenweiss avatar May 06 '20 09:05 yardenweiss

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 } }

amarvadla avatar Sep 30 '20 10:09 amarvadla

Did you ever find a solution for this?

quitequinn avatar Oct 15 '21 22:10 quitequinn

@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>

18kimn avatar Oct 18 '21 20:10 18kimn

ahh nice, thanks.

quitequinn avatar Oct 18 '21 22:10 quitequinn

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>

rodsguilherme avatar Mar 25 '22 20:03 rodsguilherme