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 {}
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.
I'd the same problem and after searching on google, following through the posts on StackOverflow & GitHub threads doesn't work out for me.
Later I realize and checked for Phantomjs and got that was missing on the server.
I installed using the below command on ubuntu server.
sudo apt-get install phantomjs
Have fun if this works for you.
I had a same issue. We were using docker for the deployment.i.e, "node:12.17.0-alpine"
I added following on Dockerfile
ENV PHANTOMJS_VERSION=2.1.1
ENV NPM_CONFIG_PREFIX=/home/node/.npm-global
ENV PATH=$PATH:/home/node/.npm-global/bin
RUN apk update && apk add --no-cache fontconfig curl curl-dev && \
cd /tmp && curl -Ls https://github.com/dustinblackman/phantomized/releases/download/${PHANTOMJS_VERSION}/dockerized-phantomjs.tar.gz | tar xz && \
cp -R lib lib64 / && \
cp -R usr/lib/x86_64-linux-gnu /usr/lib && \
cp -R usr/share /usr/share && \
cp -R etc/fonts /etc && \
curl -k -Ls https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-${PHANTOMJS_VERSION}-linux-x86_64.tar.bz2 | tar -jxf - && \
cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With