wkhtmltopdf or puppeteer in Node on Azure Linux Web App

Viewed 465

I'm struggling to make pug to pdf conversion in Node work on Azure. I have node project with two methods: one use wkhtmltopdf and is working fine on local. Another use tea-school, a wrapper that uses puppeteer to convert html to pdf, and it's also working fine on local. Unfortunately none of them is working on Azure. I was trying to make it work for 20 hours, but with no success. I know that there is Docker, but I know nothing about it and was unable to make it work.

Can you please explain how I should approach this topic? I just need to generate PDF with dynamically created data(reports,invoices etc.)

1 Answers

UPDATE

1. Azure websites and wkhtmltopdf

2. wkhtmltopdf Support in Azure Windows App RRS feed

PRIVIOUS

After consulting a lot of information, I also installed wkhtmltopdf via SSH, and found that even if wkhtmltopdf is successfully installed and environment variables are set, the pdf file cannot be generated normally.

There are also posts saying that docker is needed, or use azure cloud service.

1. Azure websites and wkhtmltopdf

2. How can i enable wkhtmltopdf in Azure windows App

You are not familiar with docker, so I recommend you to use phantom.

You can download my sample code.

app.get('/test', (req, res) => {
    try {
        phantom.create().then(function(ph) {
            ph.createPage().then(function(page) {
                page.open("http://www.google.com").then(function(status) {
                    page.render('pdf/'+uuidv4()+'test.pdf').then(function() {
                        console.log('Page Rendered');
                        ph.exit();
                    });
                });
            });
        });
        res.send('Done!')
    } catch (error) {
        res.send('Error!'+ error.toString())
    }
})
Related