We will help you tackle QXcbConnection could not connect to display wkhtmltopdf ubuntu


Install wkhtmltopdf

sudo apt-get update
sudo apt-get install wkhtmltopdf

Generate PDF File using wkhtmltopdf

wkhtmltopdf https://google.com google.pdf

After that if you get following error: 

qt.qpa.screen: QXcbConnection: Could not connect to display 

Could not connect to any X display.


Install xvfb:

sudo apt-get update
sudo apt-get install xvfb


Generate PDF File using xvfb wkhtmltopdf:

xvfb-run wkhtmltopdf https://google.com google.pdf


Create Alias:

alias wkhtmltopdf='xvfb-run wkhtmltopdf'


Use Alias:

wkhtmltopdf https://google.com google.pdf


I hope this will help you