Pass parameters to the PDF's header/footer



  • Can I pass a parameter from the PDF template to the header/footer?

    Thanks for any advice!


  • administrators

    i don't think that it is possible, but phantomjs's header/footer always inherit all the data present in its template, so maybe you just need to have all the data needed for your header available in the template

    example: https://playground.jsreport.net/studio/workspace/BkjGhA9V-/8



  • Thanks, @bjrmatos .

    I was thinking about fetching a value in the current page to the header.

    For example, if the person in the current page is "Sebastian", the header displays "Sebastian". If the person in the next page is "Mia", the name "Mia" appears in the header. Each person might have multiple pages.

    To be more specific, in https://playground.jsreport.net/studio/workspace/BkjGhA9V-/18 , is it possible to display each person's name in the header for all the pages belonging to that person?


  • administrators

    i'm afraid that it is not possible, phantomjs header/footer are very limited and what you are trying to do is to pass the current handlebars context (the current person item in the array) to the header, but phantomjs does not a have a way that let's us know when new content will appear in a new page, and practically makes impossible for us to implement more advanced features in header/footer.

    maybe you can try to play with this idea https://playground.jsreport.net/studio/workspace/BJEMYu3bb/34, it basically based on some calculations to let you know the number of pages in the report in javascript, you can also see a blog post that explains this approach for another case, maybe it will help you.



  • Thanks, @bjrmatos . I did check those ideas, but they do not work in my case since it is hard to find an accurate page size :-(



  • I basically needed the same thing. I solved it by not using external headers. Rather, I just used one big table in my template, and used the thead section to make my header... complete with variables. Worked great for me! The thead section gets repeated at the top of each page... and the variable (receipt number, in my case) gets updated with each iteration of the for loop. Using chrome-pdf.

    <style>
    table.receipt {
    page-break-before: always;
    }
    </style>
    {{for receipts}}
    <table class="receipt">
    <thead>
    <tr>
    <th class="logo">
    <img src="{#asset logo.png @encoding=dataURI}" />
    </th>
    <th class="bold center">
    <span class="big">Receipt Manager</span><br>
    CASH RECEIPT <br>
    Receipt No: {{:receiptNumber}} {{:~receiptHeader(watermark)}}
    </th>
    <th class="center school">
    {{:~root.school.name}}<br>
    {{:~root.school.address}}<br>
    {{:~root.school.city}}<br>
    {{:~root.school.phone}}
    </th>
    </tr>
    </thead>
    <tr class="receipt">
    ... all my data here ....
    </tr>
    </table>
    </div>
    {{/for}}



  • Although I don't think you could have page numbers in my example. You have to choose, one or the other (variables or page numbers).


Log in to reply
 

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