New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wkhtmltopdf: cannot connect to X server #180

Closed
daniel2d2art opened this Issue May 27, 2013 · 6 comments

Comments

Projects
None yet
5 participants
@daniel2d2art

daniel2d2art commented May 27, 2013

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

@andywenk

This comment has been minimized.

Show comment
Hide comment
@andywenk

andywenk Jul 21, 2013

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
  }
end    

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

HTH

andywenk commented Jul 21, 2013

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
  }
end    

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

HTH

@cdwort

This comment has been minimized.

Show comment
Hide comment
@cdwort

cdwort Aug 24, 2013

Contributor

@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.

Contributor

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

@daniel2d2art

This comment has been minimized.

Show comment
Hide comment
@daniel2d2art

daniel2d2art Sep 16, 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)

daniel2d2art commented Sep 16, 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)

@timothymarois

This comment has been minimized.

Show comment
Hide comment
@timothymarois

timothymarois Jul 7, 2016

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.

timothymarois commented Jul 7, 2016

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.

@timothymarois

This comment has been minimized.

Show comment
Hide comment
@timothymarois

timothymarois Jul 7, 2016

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.

timothymarois commented Jul 7, 2016

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.

@alexburcea2877

This comment has been minimized.

Show comment
Hide comment
@alexburcea2877

alexburcea2877 Dec 6, 2017

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
--2017-12-06 19:23:04-- http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
Resolving wkhtmltopdf.googlecode.com (wkhtmltopdf.googlecode.com)... 2607:f8b0:400e:c00::52, 173.194.202.82
Connecting to wkhtmltopdf.googlecode.com (wkhtmltopdf.googlecode.com)|2607:f8b0:400e:c00::52|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-12-06 19:23:04 ERROR 404: Not Found.

alexburcea2877 commented Dec 6, 2017

wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
--2017-12-06 19:23:04-- http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
Resolving wkhtmltopdf.googlecode.com (wkhtmltopdf.googlecode.com)... 2607:f8b0:400e:c00::52, 173.194.202.82
Connecting to wkhtmltopdf.googlecode.com (wkhtmltopdf.googlecode.com)|2607:f8b0:400e:c00::52|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2017-12-06 19:23:04 ERROR 404: Not Found.

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