Add a watermark to second of 3 PDF's
-
I am using this post as a reference. I have a pdf that has 3 pages. I only want to merge a watermark on the second one. Is this possible with pdfUtils?
const jsreport = require('jsreport-proxy') async function afterRender(req, res) { const watermarkRes = await jsreport.render({ template: { name: 'Watermark' } }) const $pdf = await jsreport.pdfUtils.parse(res.content) const pagesToMerge = new Array($pdf.pages.length).fill(watermarkRes.content) const originalBuffer = Buffer.from(res.content) const withWatermarkBuffer = await jsreport.pdfUtils.merge(originalBuffer, pagesToMerge) res.content = await jsreport.pdfUtils.append(res.content, withWatermarkBuffer) }
-
You could do this without an extra script.
Like this
https://playground.jsreport.net/w/anon/QPxS7qHE
-
@admin that works. thanks
-
@admin I actually have another scenario. In the watermark template I need to be able to access the data passed into the parent template. Is that possible?
-
The input data from the original template are forwarded to the rendering of the pdf operation.
-
@admin thanks for pointing that out. I had to prefix the data with @root because I was inside an iteration.