jsreport / jsreport-pdf-utils

jsreport extension providing pdf operations like merge or concatenation
MIT License
8 stars 4 forks source link

Add a watermark to second of 3 PDF's #35

Closed iii-james closed 1 year ago

iii-james commented 1 year ago

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)
}
iii-james commented 1 year ago

probably the wrong place for a general question. closing and moving it to the forum.