i have EC2 instance running in aws. after i deploy to the server. all workking fine until i check html-pdf. everytime i hit the api to create pdf, i check the log and the result is:
i already try to unninstall html pdf using npm uninstall html-pdf then install again with npm install html-pdf
and i already try with npm link phantomjs-prebuilt but still have the same result. when i check with local everything working fine, does anyone have same issue like this and already solved? thanks!
*update:
i already try with install phantomjs global, and set the phantom path using:
"phantomPath":"../../../../../usr/local/lib/node_modules/phantomjs-prebuilt/bin/phantomjs"
the path i got from the node modules:
this is my code:
createOwn: async function (req, res, next) {
try {
const owner = await getOwnership(req.params.id);
const name = await Date.now();
ejs.renderFile(path.join(__dirname, './template', "own.template.ejs"), { own: owner, moment: moment, }, (err, data) => {
if (err) {
console.log(err);
return res.status(500).json({ status: "error", data: err });
} else {
let options = {
"format": "A4",
"orientation": "portrait",
"phantomPath": "../../../../../usr/local/lib/node_modules/phantomjs-prebuilt/bin/phantomjs",
"border": {
"top": "1cm", // default is 0, units: mm, cm, in, px
"right": "2cm",
"bottom": "1cm",
"left": "1cm"
},
};
pdf.create(data, options).toFile(`temp/${name}.pdf`, function (err, data) {
if (err) {
console.log(err)
res.send("cannot create pdf");
} else {
var file = `temp/${name}.pdf`;
fs.readFile(file, function (err, data) {
res.contentType("application/pdf");
res.send(data);
});
}
});
}
});
} catch (e) {
console.log(e)
return res.status(500).json({ status: "error", data: "internal server error" });
}
},
To resolve this issue please go to the
node_modules folder through terminal and use the command
sudo node ./install.js
orsudo node ./install.js -f
this will definitely install this module.