Solved - QXcbConnection could not connect to display wkhtmltopdf ubuntu

By Hardik Savani | June 30, 2020 | Category : Ubuntu


Do you have issue with wkhtmltopdf install in ubuntu linux then i will help you how to solve that error. if you have error like qxcbconnection: could not connect to display wkhtmltopdf ubuntu.

When i installed wkhtmltopdf on my ubuntu server and i run wkhtmltopdf command to generate pdf file from url. then i got following issue:

"forge@billowing-star:~$ wkhtmltopdf http://www.google.com google.pdf

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

Could not connect to any X display."

if you have same issue then i will help you how to resolve that issue using xvfb-run command. so let's see bellow step by step instruction.

Install wkhtmltopdf

sudo apt-get update

sudo apt-get install wkhtmltopdf

After install wkhtmltopdf successfully, you can run following command to generate pdf fie from url. so let's run bellow command:

Generate PDF File using wkhtmltopdf

wkhtmltopdf https://google.com google.pdf

After that if you receive error like as bellow:

Get Error Like bellow:

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

Could not connect to any X display.

Now you can resolve that error using xvfb command, so let's run bellow command:

Install xvfb:

sudo apt-get update

sudo apt-get install xvfb

now you can easily generate pdf file using $ xvfb-run wkhtmltopdf command as bellow:

Generate PDF File using xvfb wkhtmltopdf:

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

Now it should generate pdf file.

you can also create alias for xvfb-run wkhtmltopdf as like bellow:

Create Alias:

alias wkhtmltopdf='xvfb-run wkhtmltopdf'

Use Alias:

wkhtmltopdf https://google.com google.pdf

I hope it can help you...



Tags : Ubuntu


Hardik Savani
My name is Hardik Savani. I'm a full-stack developer, entrepreneur and owner of Aatman Infotech. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.
Follow Me: Github Twitter
***Do you want me hire for your Project Work? Then Contact US.

We are Recommending you: