Show blocks only on the last page using pdf utils



  • I need to show an html block only on the last page of the report.
    Using a script I'm able to hide the block only on the first page, on the next pages the blocks is always visible.
    Using phantom-pdf instead of chrome-pdf+pdf-utils it works fine.

    I shared an example to better understanding: https://playground.jsreport.net/w/sguidotto/3eDStYM6
    The script is this below, it is on the headerfooter template called by pdf-utils from the main template:

    <!---------------------------- Show blocks on last page-------------------------->
    <script>
        if (document.getElementById("pagenumber").innerHTML < document.getElementById("totalpages").innerHTML) {
            document.getElementById("Totals").style.display = "none";
        } else {
            document.getElementById("Totals").style.display = "block";
        }
    </script>
    

    Any suggestion is welcome. Thank you :-)



  • You can use handlebars to reach this

    {{#if @last}}            
                    <table id="Totals" class="full-width" > 
    {{/if}}
    

    Or implement your own helper if you need some extra logic

    // helper
    function ifLastPage(index, options) {
        if (options.data.root.$pdf.pages.length - 1 === index) {
            return options.fn(this)
        }
        return ''
    }
    

    https://playground.jsreport.net/w/anon/sdmLVf74


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.