Thank you for sharing.
I have a problem though. My document is made up of a main template and a header-footer template that I merge with PDF-Utils (in the GUI).
Using this snippet of code I have the correct number of pages, and on the second set of pages I have a watermark but I lose the header/footer..
Any idea? Maybe because the GUI pdfUtils is run after render?
in any case I've tried to programmatically read the template and merge it and then merge over the watermark, but I don't seem to be able..
const jsreport = require('jsreport-proxy')
async function afterRender(req, res) {
//this is the watermark
const duplicateRes = await jsreport.render({
template: {
name: 'watermark'
}
})
const $pdf = await jsreport.pdfUtils.parse(res.content)
const pagesToMerge = new Array($pdf.pages.length).fill(duplicateRes.content)
const originalBuffer = Buffer.from(res.content)
//now add header-footer
const corniceRes = await jsreport.render({template: {name: 'header_footer' }})
const pagesToMergeCornice = new Array($pdf.pages.length).fill(corniceRes.content)
const corniceBuffer = await jsreport.pdfUtils.merge(originalBuffer, pagesToMergeCornice)
//
const withDuplicateBuffer = await jsreport.pdfUtils.merge(corniceBuffer, pagesToMerge)
res.content = await jsreport.pdfUtils.append(res.content, withDuplicateBuffer)
}
Thanks
Z