CloudConvert Combine Docx and PDF

525 views Asked by At

Im using the CloudConvert NodeJS Package. I have a process that grabs a PDF from a remote server and then generates a docx dynamically from a template. I am attempting to use CloudConvert to combine these two pdfs, but whenever I do so the returned document is just the docx repeated twice.

I've confirmed that CloudConvert is requesting both the PDF and the Docx, and not just the docx twice. If i replace the Docx with another PDF it will combine the two successfully, but the combination of the both seems to not work well, even though their documentation states that it is supported.

Here's my code, it's essentially the example code modified to include my local documents, I've simplified a few of the paths and remove my domain information but besides that, it's true to how I've implemented it.

cloudconvert.createProcess({
    "mode": "combine",
    "outputformat": "pdf"
}, function(err, process) {
    if (err) {
        console.error('CloudConvert Process failed: ' + err);
    }                            

    process.start({
        "mode": "combine",
        "input": "download",
        "files": [
            '*domain*/packingslips/'+transaction.object_id+'.docx',
            '*domain*/shippinglabels/'+transaction.object_id+'.pdf'
        ],
        "outputformat": "pdf",
        "wait": true
    }, function(err, process){
        if (err) {
            console.error('CloudConvert Process failed: ' + err);
        }

        process.wait(function(err, process){
            if (err) {
                console.error('CloudConvert Process failed: ' + err);
            } else {
                console.log('Done: ' + process.data.message);    
                process.download(fs.createWriteStream('/integration/combinedpdfs/'+transaction.object_id+'.pdf'), null, function (err, process) {
                    if (err) {
                        console.error('CloudConvert Process download failed: ' + err);
                    } else {
                        console.log('Downloaded to ' + '/integration/combinedpdfs/'+transaction.object_id+'.pdf');
                    }
                });
            }                                    
        })
    });
});
1

There are 1 answers

0
monday On

Each input file has to have an unique filename. You can override the input name using the filename parameter. In your case:

process.start({
    "mode": "combine",
    "input": "download",
    "files": [
        {"file": '*domain*/packingslips/'+transaction.object_id+'.docx', "filename": "template.docx"},
        {"file": '*domain*/shippinglabels/'+transaction.object_id+'.pdf', "filename": "other.pdf"}
    ],
    "outputformat": "pdf",
    "wait": true
}, ...)