Warm tip: This article is reproduced from serverfault.com, please click

PDF file creation using html-pdf is not working in my deployment server?

发布于 2016-05-21 13:04:50

I am using html-pdf npm module to create a pdf file, everything is working fine in my local environment (mac, windows). But when we deployed the same code in our amazon ec2 server create() of html-pdf is not able to create file nor giving me any error. I almost tried all possible ways by exception handling, absolute path etc. None of them work. Can anyone help me on this please. my code is

function generatePdf(content, options, callback) {
    var fileName = new Date().getTime() + Math.random() + '.pdf';
    pdf.create(content, options).toFile('../uploads/' + fileName, function(error, response) {
        if (error) {
            callback(error);
        } else {
            callback({
                fileName: fileName,
                filePath: response.filename
            });
        }                                
    });
}

Here error is {} and the response is {}

Questioner
Syam Danda
Viewed
0
3,425 2020-08-19 05:14:05

There is absolutely nothing wrong with the above code. However, the reason why html-pdf lib is not throwing any error nor creating a file while pdf.create(...).toFile is due to the errors in html-pdf installed version in your environment. We can determine it by checking

npm list html-pdf and if returns anything like npm ERR! code 1 then do

npm uninstall html-pdf and then do again
npm install html-pdf 

and repeat above step to make sure there are no errors in current installed version of html-pdf.