3

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.)

Daniel Więcek
  • 625
  • 1
  • 10
  • 16
  • Has your problem been solved? Is there any progress? – Jason Pan Mar 03 '21 at 03:41
  • Thanks for tips Jason :) I have some higher priority work to do for this week. I'll try this next week. As soon as it'll work I'll accept your answer or post some question if it doesn't. – Daniel Więcek Mar 03 '21 at 20:39

1 Answers1

0

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())
    }
})
Jason Pan
  • 15,263
  • 1
  • 14
  • 29
  • Hi Jason. Unfortunately phantom also didn't work. The error is similar to wkhtml and puppeteer: A library is missing: "error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory". – Daniel Więcek Mar 16 '21 at 20:39
  • @DanielWięcek I have updated my answer, pls check it. – Jason Pan Mar 25 '21 at 01:17
  • @DanielWięcek If my reply is helpful, please accept it as answer(click on the mark option beside the reply to toggle it from greyed out to fill in.), see https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work – Jason Pan Mar 25 '21 at 01:17
  • 1
    Your reply wasn't helpful for me, but it might be for someone else. Here is how you can update it to get precious green thick ;) All of those 3 libs: wkhtml, puppeteer, phantom need some linux libs to be installed. Firstly - I can do this using SSH page in azure - a ssh console(I didn't know that before) to install the missing libs manually after deployment. Moreover wkhtml and puppeteer libs required multiple linux libs(about 95MB) and phantom required only libfontconfig(5MB). Downside is that I need to install the lib after every deployment. But I can create a script to do this. – Daniel Więcek Mar 25 '21 at 12:00