Iterating over pdfs that are more than 1 page long
-
https://playground.jsreport.net/w/ayseboogie/98R5k3~l
In this playground, the first page of each data set is shown - Test Device and Test Device 2. I am having the issue of my pdfs getting cut off after the first page when using an array template. In the data for Test Device, "name": "item x" goes up to 60 but in templateArray, is cut off after 53 because the rest of the data is on a new page. How would we handle a situation where we are processing an array of data to create multipage pdfs and want to combine those all into one? - ie Test Device data in full, page break, Test Device 2 data in full?
We have multiple multi-page invoices and we are wanting JSReport to give us all of them in 1 document from an array datasource
-
I am not sure if I get it fully... However, you can dynamically render multiple templates and append them in the script.
const jsreport = require('jsreport-proxy') async function afterRender (req, res) { const results = await Promise.all( req.data.devices.map(d => jsreport.render({ template: { name: 'normalTemplate'}, data: d }))) let currentBuffer = results.shift().content for (const r of results) { currentBuffer = await jsreport.pdfUtils.append(currentBuffer, r.content) } res.content = currentBuffer }
-
That's exactly what I was looking for! Thank you very much.