Another day, another thing. I’m running a PHP site on Azure App Service, the site needs to convert some documents to pdf. We know we need wkthmltopdf, unfortunately the default image doesn’t have it, we need to do it ourself.

First i install wkhtmltopdf – it seems pretty simple:

apt-get install wkhtmltopdf

It installed successfully, unfortunately when we run it, we got this error:

QXcbConnection: Could not connect to display
Aborted (core dumped)

Google the error and found the recommendation is to run like this: xvfb-run wkhtmltopdf -q test.html test.pdf

I tried that, unfortuately, it said xvfb-run not found.

OK, let install it: apt install xvfb

After it’s installed successfully, run xvfb-run wkhtmltopdf -q test.html test.pdf and it works perfectly.