Merge external PDF into recipe



  • Hello, I was wondering if its possible in the jsreports system to pass through an external pdf in base64 or any other format and merge it into a recipe I have created for making a report?

    Regards
    Michael



  • Yes, you can use a custom jsreport script where you can code what you need
    https://jsreport.net/learn/scripts
    https://jsreport.net/learn/pdf-utils#usage-in-script

    const jsreport = require('jsreport-proxy')
    async function afterRender (req, res) {
        res.content = await jsreport.pdfUtils.merge(res.content, Buffer.from(req.data.externalPdf, 'base64'))
    }
    

    Full demo here
    https://playground.jsreport.net/w/anon/2lCyXIBl



  • I’ve run into similar issues when trying to pull in external PDFs that weren't generated by the same template. Using the pdf-utils 'merge' or 'append' operations is definitely the way to go, but it can get a bit finicky if the source files have different page sizes or metadata.
    If you're still having trouble getting the pages to line up, one thing that helped me was to 'pre-process' the external files first to make sure they're cleaned up or split into the exact pages you need before calling them in the recipe. It’s a bit of an extra step, but it usually stops those weird layout shifts or empty pages from happening during the merge!


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.