How to get in chrome-pdf headers/footers?

  • I've got a beforeRender script tied to an HTML template which is also tied to an identical PDF. It loads some stuff that I'm using for a report header in my HTML version, and I'd like to reuse it in my page headers for my PDF version. But the PDF header doesn't seem to be getting the data from the main template's script. Do I need to run another script for the header instead? Would this cause it to run for each page? How do I get to PDF sub-templates using PDF-utils?

  • I see that I'm supposed to have the data available. I've been trying to figure out why it isn't working without luck so far. If I find anything out, I'll add it here.

  • administrators

    hi! i think the best in this case will be to see an example of what you are trying in the playground, can you share an example?

  • Weird. I detached the header from the main PDF and reattached another with identical contents and now it works. The new one is in the same folder. The first attempt was in the parent folder. Should that matter? Anyway, it's working now.

  • administrators

    i think it should not matter because the code makes sub template inherit the data no matter the hierarchy in folders.. anyway if you experience this again you can share an example on playground even an export zip file with me.

  • I discovered why it started working. Initially, I did check the box to "Render on Every Page". With this checked, I was getting the error: "Error: Timeout during evaluation of pdf-utils operations"

    When I deleted that header row in the PDF-utils configurator and added it back in, I forgot to check the box the second time. So I agree with bjrmatos that it shouldn't have mattered which folder the template was in. But, having forgotten to check the box the second time, it worked.

    Note that even without the box checked, it was rendering the header on every page. So I tried the same thing with the footer. It worked too - except that {{$pdf.pageNumber}} wouldn't work. So I went looking for a solution, but eventually just tried to check the box I mentioned - but only for the footer. That fixed it, but the render does take a lot longer now. I'm nervous to run a really long report. Will it time out? I hope not. I guess we'll see.

  • administrators

    you can avoid rendering for each page and preserving the "pageNumber" by using the "merge whole document" checkbox. here is an example of template with header and footer using that approach. maybe you can try that and you won't be rendering a template per page, but instead a single render for all header/footer in pages

Log in to reply

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