marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 545 forks source link

set page number in footer with logic? #572

Open yardenweiss opened 4 years ago

yardenweiss commented 4 years ago

there is a way to calculate and display the page number with some index ? something like this ?

options.footer = { height: '50px', contents: { default: `

{{page + index}}
          `
        }
amarvadla commented 3 years ago

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

quitequinn commented 2 years ago

Did you ever find a solution for this?

18kimn commented 2 years ago

@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>
quitequinn commented 2 years ago

ahh nice, thanks.

rodsguilherme commented 2 years ago

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>