page numbers with pdf utils and skip footer on cover page



  • Hello @jan_blaha @bjrmatos

    Hope you're doing great!

    I'm using pdf utils to append and prepend some pages based on requirements. but having some issues with page number when I am appending different pages.

    I need something like below:

    1. Cover page (Skip footer)
    2. Some pages based on data (first page footer will be different)
    3. Cover page again (Skip footer)
    4. Some pages based on data (first page footer will be different)

    Here is an example playground [run mainTemplate1]

    I've achieved most of the requirements, but I'm having trouble with page numbers. If I use utils order in such a way that page numbers are sequential, I cannot skip the second cover page, and if I skip the cover page, the page numbers start from the first number to the appended pages.

    Is there any way so that we can skip cover page and other pages page number can be in sequence

    Thanks!



  • I don't know if this will work for you or its the best approach but lets start with this...

    How about you add to the cover pages a special marking, that the header merge should be skipped?

    {{{pdfAddPageItem "Cover"}}}
    

    And then reach this information when rendering header template.

    function notCover(index, opts) {    
        if (opts.data.root.$pdf.pages[index].items.find(i => i === 'Cover')) {        
            return
        }
        return opts.fn(this)
    }
    

    Demo here
    https://playground.jsreport.net/w/anon/Id5j2vIo



  • Hey @jan_blaha Thanks! for your quick help. It worked for me.

    Having one issue with this solution, I have implemented it in my project but sometimes it throws the following error and sometimes it works perfectly! not sure why!!

    If you can take a quick look at this that will be great! Thanks!

    
      130 | // hide footer if page is set to hideFooter
      131 | handlebars.registerHelper('renderFooter', (index, opts) => {
    > 132 |     if (opts.data.root.$pdf.pages[index] && opts.data.root.$pdf.pages[index].items.find(i => i === 'hideFooter')) {        
          |                                                                                    ^
      133 |         return
      134 |     }
      135 |     return opts.fn(this)
    
    
        at module.exports (/app/node_modules/jsreport-core/lib/util/createError.js:11:13)
        at Reporter.createError (/app/node_modules/jsreport-core/lib/reporter.js:332:12)
        at AsyncFunction.<anonymous> (/app/node_modules/jsreport-pdf-utils/lib/main.js:382:22)
        at processTicksAndRejections (internal/process/task_queues.js:97:5)
    caused by: Error: Error while executing templating engine. Cannot read property 'find' of null. Error on line 132:84.
    
      130 | // hide footer if page is set to hideFooter
      131 | handlebars.registerHelper('renderFooter', (index, opts) => {
    > 132 |     if (opts.data.root.$pdf.pages[index] && opts.data.root.$pdf.pages[index].items.find(i => i === 'hideFooter')) {        
          |                                                                                    ^
      133 |         return
      134 |     }
      135 |     return opts.fn(this)
    
    
        at process.<anonymous> (/app/node_modules/script-manager/lib/worker-processes.js:55:23)
        at process.emit (events.js:311:20)
        at emit (internal/child_process.js:876:12)
        at processTicksAndRejections (internal/process/task_queues.js:85:21)```


  • You seem to use quite an old version, I'm not sure now if it is some kind of bug or not. Does it fail the same with the latest? Would you be able to provide something we can replicate?


Log in to reply
 

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