Solved - Qxcbconnection: Could Not Connect To Display wkhtmltopdf on ubuntu - How To Fix it?

Solved - Qxcbconnection: Could Not Connect To Display wkhtmltopdf on ubuntu - How To Fix it?

Hello Devs.

Today, we will solve an error “Qxcbconnection: Could Not Connect To Display wkhtmltopdf” on ubuntu. You need to just install the xvfb from apt to solve this error. You can run xvfb-run wkhtmltopdf 

Install wkhtmltopdf

sudo apt-get update
sudo apt-get install wkhtmltopdf

Generate PDF from URL

After installing wkhtmltopdf on ubuntu, you can generate pdf file from url with following command. 

wkhtmltopdf https://google.com google.pdf

Got an error?

But if you face an error like this

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

Could not connect to any X display.

You can easily resolve this error by just installing xvfb by following the command. it's good solution for qxcbconnection: could not connect to display.

Step 1: Install xvfb to fix above error

sudo apt-get update
sudo apt-get install xvfb

After install xvfb you can generate pdf files from url without any error with the following command. 

Step 2: Generate PDF using xvfb

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

Now it should generate PDF file from url using above mentioned command. You can make the command more simple by creating an alias for xvfb-run. Just run the following command to make alias. 

Step 3: Make Alias for xvfb-run

alias wkhtmltopdf='xvfb-run wkhtmltopdf'

Now you can simply run this following command to generate PDF file from URL. 

wkhtmltopdf https://google.com google.pdf

 

I hope, it will be helpful to solve your error. 

Happy Coding :)

Leave a Comment

Your email address will not be published. Required fields are marked *

Go To Top
×