'Page number in jsreport

Is it possible to display page number in jsreport? I couldn't find this either on the homepage of the tool nor by googling.

Many thanks in advance!



Solution 1:[1]

I assume you ask for page numbers in a pdf report created by phantom-pdf recipe...

You can use special tags {#pageNum} and {#numPages} in template.phantom.header for this:

<div style='text-align:center'>{#pageNum}/{#numPages}</div>

Note you can use also javascript in header/footer to customize visibility or value of the page numbers.

<span id='pageNumber'>{#pageNum}</span>
<script>
    var elem = document.getElementById('pageNumber');
    if (parseInt(elem.innerHTML) <= 3) {
        //hide page numbers for first 3 pages
        elem.style.display = 'none';
    }
</script>

Documentation here

UPDATE 2022:
jsreport now uses primarily chrome for generating pdf. You can now add page numbers using native headers or in complex cases using pdf utils

pdf utils based header playground example can be found here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1