Slow pdf-utils merge with "Render for every page"
-
A scenario I'm investigating is having a report with a header that reflects the information of the page it's on. I've used the new pdf-utils & the {{{pdfCreatePagesGroup ...}}} functionality to technically get what I want, but it is too slow for production.
I've just done some basic profiling, and my 60page base report renders:
- in 6s with static header/footer
- in 90s with dynamic header/footer by merge with "Render for every page" turned on
Digging around in the pdf-utils merge code, it's rendering a report for every page (which makes sense).
I next had the idea to try rendering a second 60page report that consists of just the dynamic page headers and merging it to the base report with "Render for every page" turned off. I was speculating that it would run in about 2x the time rather than 15x. But that only prints page 1 of the 2nd report onto each page of the base report because it restarts (so it's effectively a static header).
What I was wondering is if there's a way to render the base report, then merge a 2nd report over top of it and don't restart on page 1 of the 2nd report for each page of the base? i.e. page N of the final report has page N of the base report and page N of the 2nd report.
Or if there isn't currently, if that's something on the roadmap? Taking a peak around in the pdf-utils code, it appears to be possible, but would need a clear UI and api to select that option.
-
We have in backlog a task for reusing chrome instance over multiple requests. This should bring performance boost to pdf utils.
https://github.com/jsreport/jsreport-chrome-pdf/issues/8However your idea is very interesting. It would bring better performance gain. How it would work...
The main content would run normally.
We would parse the pdf as we do with selected "Render for every page" afterwards.
The merge operation would run single template which could use templating engine "loop" to iterate over parsed pages and render one long pdf.{{#each $pdf.pages}} <div> dynamic header from current page</div> <div class='page-break'/> {{/each}}
That would get merged into the original pdf. This means there would be only two pdf rendering.
Do I get it right?
-
Yeah, that's exactly the sort of thing I was thinking. In my case there would always be the same number of pages in both, but I guess the solution should handle where the number of pages differs.
I'll keep an eye on the reusing chrome issue as well. That sounds like a really cool improvement too.
-
You can subscribe here to get notification about the progress.
https://github.com/jsreport/jsreport-pdf-utils/issues/10
-
This now implemented. See this for details
https://github.com/jsreport/jsreport-pdf-utils/issues/10