Merge Error When 2 different pages are prepend before TOC using pdfAddPageItem pageBeforeTOC=true



  • I am trying to add two pages before TOC- say 'title page' and 'disclaimer' page.

    The final merged PDF should look like [title, disclaimer, toc, main]

    The approach I am taking is:
    I am adding {{{pdfAddPageItem pageBeforeTOC=true}}} on both title and disclaimer template which has to appear before toc.

    //disclaimer template
    <p><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></p>
    {{{pdfAddPageItem pageBeforeTOC=true}}} <p>This is Disclaimer Page</p>
    
    //Title page template
    <p><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR></p>
    {{{pdfAddPageItem pageBeforeTOC=true}}} <p>This is Title Page</p>
    

    And in toc, I am adding empty pages using helper function:

    {{#each (getPagesBeforeTOC @root)}}
        <!-- in order to produce a new page there must be some element before -->
        <div style="visibility: hidden;">&nbsp;</div>
        <div style="page-break-before: always;"></div>
    {{/each}}
    

    However, this is crashing:

    Error: Error while executing pdf-utils operations. incorrect header check
        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)
    caused by: Error: incorrect header check
        at Zlib.zlibOnError [as onerror] (zlib.js:180:17)
        at processChunkSync (zlib.js:426:12)
    
    

    Any help is appreciated.

    Here is the narrowest version of the replicator:
    https://playground.jsreport.net/w/anon/xSDm7AJx

    Please note, If I add only one page before TOC, then it works perfectly without any problem. You can check this by disabling any of the title or disclaimer items in the main pdf-utils merge operation.

    0_1626536172393_upload-8d7524ac-24a5-4d16-803b-9f6659669dd8

    In most of the use cases, to create any report "multiple pages with the headers footers+page number" are required to prepend before TOC. Hence, I am looking for a robust solution for this, if my approach above is not the correct one.

    Thanks.



  • Thank you for the demo.

    The following is the problematic place

    {{#each (getPagesBeforeTOC @root)}}
        <!-- in order to produce a new page there must be some element before -->
        <div style="visibility: hidden;">&nbsp;</div>
        <div style="page-break-before: always;"></div>
    {{/each}}
    
    

    Chrome prints completely empty page buffer when applying this HTML. This makes problems to the jsreport-pdf-utils now. You can change it with something like this. It shouldn't make layout difference but makes the pdf merge happy.

    {{#each (getPagesBeforeTOC @root)}}
        <!-- in order to produce a new page there must be some element before -->
         <div style="display: inline-block;font-size:1.1px;">&nbsp;</div>
        <div style="page-break-before: always;"></div>
    {{/each}}
    

    We will make sure pdf utils can handle also the original code in the next release.



  • @jan_blaha : Amazing. It works. I should have posted this query much earlier, spent 2 days in digging out why it's crashing. Thanks again a ton. :)


Log in to reply
 

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