jsreport

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

  • 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.