wkhtmltopdf: cannot connect to X server #180

daniel2d2art opened this Issue May 27, 2013 · 5 comments


None yet

4 participants


Hi here
This is working Ok from console Centos 6.x:

wkhtmltopdf --print-media-type --use-xserver --quiet www.google.com ~/google.pdf

But when working from pdfkit v0.5.3 gem in RoR v3.2.1

RuntimeError (command failed: "/usr/local/bin/wkhtmltopdf" "--print-media-type" "--use-xserver" "--quiet" "-" "-"

And Apache error:

wkhtmltopdf: cannot connect to X server

We're using Xvfb as Xserver


I had the same issue on Ubuntu Linux. The problem is, that the standard installation of wkhtmltopdf, requires an xserver. You should download a precompiled version. Do this:

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
sudo mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
sudo chmod +x /usr/local/bin/wkhtmltopdf

now try it:

/usr/bin/wkhtmltopdf --page-size A4 --quiet http://google.com google.pdf

if that works, put this to /config/initializers/pdfkit.rb

PDFKit.configure do | config |
  config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
  config.default_options = {
    :page_size => 'A4',
    :print_media_type => true

This should be a solution you can adapt for Centos ...


cdwort commented Aug 24, 2013

@andywenk Thanks for the explanation. As there appears to be a solution, I am closing this issue, but have noted that it requires additional documentation.

@cdwort cdwort closed this Aug 24, 2013

we're using precompiled version and Xvfb as Xserver
Same installation procedure works on other SO like ubuntu but not works on Centos 6.x.
(and Not selinux problem)


I'm sorry that this is an incredibly old thread, but I've been trying to overcome the same error. On Red Hat (64-bit). wkhtmltopdf: cannot connect to X server No matter what I do. Ive installed via the steps above and have installed via sudo yum, both success. But when running the wkhtmltopdf command, it shoots out that error message.


I think I've figured it out need to have xorg-x11-server-Xvfb installed for Redhat. I'll continue to see if everything else functions as normal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment