Syam Danda Syam Danda - 1 year ago 78
Node.js Question

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

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) {
} else {
fileName: fileName,
filePath: response.filename

Here error is {} and the response is {}

Answer Source


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.