I'm trying to use wicked_pdf on my prod server but it keeps failling :
RuntimeError (Failed to execute:
"/usr/bin/wkhtmltopdf" -q "file:////tmp/wicked_pdf20130709-23109-1adqx5g.html" "/tmp/wicked_pdf_generated_file20130709-23109-1ic5dbe.pdf"
Error: PDF could not be generated!
Command Error: wkhtmltopdf: cannot connect to X server
):
app/controllers/contrats_controller.rb:15:in `block (2 levels) in show'
app/controllers/contrats_controller.rb:11:in `show'
I tried to follow this answer : wkhtmltopdf: cannot connect to X server but it still does not work.
Resolved this problem in this tread https://stackoverflow.com/a/34947479/5320149
I found method to resolve this problem without fake X server. In newest version of wkhtmltopdf dont need X server for work, but it no into official linux repositories.
Solution for Ubuntu 14.04.4 LTS (trusty) i386
Solution for Ubuntu 14.04.4 LTS (trusty) amd64
This post helped me to resolve my problem : http://www.stormconsultancy.co.uk/blog/development/generating-pdfs-in-rails-with-pdfkit-and-deploying-to-a-server/
I'm reproducing here the step from this post that helped me to install it :
He also create an initializer to tell to pdfKit where it is, so this method is for wicked PDF and PDF Kit.
Verify you have
xvfb
installed, or install it usingapt-get install xvfb
.Create a file called
wkhtmltopdf.sh
and add the following:Change the dimensions (640x480x16) to match whatever virtual screen parameters you want it to emulate.
Move the shell script to
/usr/bin
, and set permissions:Optionally, you can add a symbolic link in your project directory:
See this and this for reference.