Solved - QXcbConnection could not connect to display wkhtmltopdf ubuntu

By Hardik Savani May 1, 2024 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 :
Shares