nbesli/pdf-merger-js

merger.save() actually merge old merged pdf with new merged pdf,

AbhayKrSing opened this issue · 2 comments

const PDFMerger = require('pdf-merger-js');
const merger = new PDFMerger();
const multer = require('multer')
const upload = multer({ dest: 'uploads/' })

app.post('/merge', upload.array('files', 12), async (req, res) => {
    try {

        const files_array = req.files    //file coming from front end side (using react)
        console.log(files_array)  
    
        for (value of files_array) {
            await merger.add(`./uploads/${value.filename}`);
        }

        await merger.save('./Merged-files/merged.pdf')     //It merge old merged pdf with new merged pdf if above api call in short interval.
        res.status(200).send({ success: 'Done successfully merged' })
        for (value of files_array) {
            fs.unlinkSync(`./uploads/${value.filename}`)
        }

    } catch (error) {
        console.log(error.message)
    }

})

Same issue with me

dublicate of #99

You need to create a new instance of PDFMerger for each document at the moment.
This will be solved with #111 in the future.