marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 543 forks source link

html-pdf npm library gives weird output on Linux Server? #492

Open vinodgupta2006 opened 5 years ago

vinodgupta2006 commented 5 years ago

I am generating PDF from HTML and that worked fine on my local machine, which has Windows as OS. But now I deploy my application on a Linux server where it gives weird output:

const htmlPdf = require('html-pdf')
try{
    let html = `<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8" /></head><body><div>Managed APs</div><br /><table><th>AP Serial</th><th>AP Name</th><th>AP Model</th><th>Mac Address</th><th>IP</th><th>Connect Status</th><th>Cluster</th><tr><td>1010212112</td><td >AP_Test</td><td>RJ147</td><td>1.23.2.2</td><td>1.23.12.4</td><td>Connected</td><td>Dummy Cluster</td></tr></table></body></html>`

    htmlPdf.create(html).toBuffer(function(err, buffer){
        if(err){
            return res.json({
                success: false,
                message: dbErrorMessage
            });
        } else{
            const pdfData = buffer.toString('base64')
            return res.json({
                success: true,
                data: pdfData
            });
      }
    });
}
catch(e){
    return res.json({
        success: false,
        message: e 
    });
}

I have also posted query on stackoverflow: https://stackoverflow.com/questions/53866694/html-pdf-npm-library-gives-weird-output-on-linux-server

Sairam-Ch commented 5 years ago

I am also facing the same issue, it is working fine in local but in linux server not working buffer output value gives as a 'undefined'

ganeshpaiya commented 5 years ago

I am also facing the same issue, it is working fine in local but in linux server not working buffer output value gives as a spawn /var/projects/dev/facommtrack/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe ENOENT

Sairam-Ch commented 5 years ago

@ganeshpaiya I was faced the same issue, If you update the phantomjs in your server then you may not get this issue.along with that in your server update the below packages too. It was works fine to me now. sudo apt-get install libfreetype6 sudo apt-get install libfontconfig

RobertDS07 commented 3 years ago

For alpine it in Dockerfile was works fine

RUN apk add --no-cache curl && \ cd /tmp && curl -Ls https://github.com/dustinblackman/phantomized/releases/download/2.1.1/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-2.1.1-linux-x86_64.tar.bz2 | tar -jxf - &&\ cp phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/local/bin/phantomjs && \ rm -fR phantomjs-2.1.1-linux-x86_64 && \ apk del curl

RUN npm rebuild phantomjs-prebuilt

RobertDS07 commented 3 years ago

And don't forgot libconfig