Read more

Fix „command failed: /usr/bin/wkhtmltopdf ...“ using PDFKit middleware

Martin Straub
November 04, 2013Software engineer at makandra GmbH

Ubuntu 12.04 LTS x64, Ruby 1.8.7, Rails 2.13, PDFKit 0.5.4, Phusion Passenger Apache 2

Illustration web development

Do you need DevOps-experts?

Your development team has a full backlog? No time for infrastructure architecture? Our DevOps team is ready to support you!

  • We build reliable cloud solutions with Infrastructure as code
  • We are experts in security, Linux and databases
  • We support your dev team to perform
Read more Show archive.org snapshot

I ran into this, when I started using passenger to deal with the Single Thread Issue Show archive.org snapshot which caused my webrick to deadlock when an ActionController::RoutingError (No route matches "...") occurred.

These steps brought me a little further

(1) assert dependencies are installed

 sudo aptitude install openssl build-essential xorg libssl-dev

(2) only for 64bits OS Run one by one the following commands:

sudo wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
sudo 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

Tell PDFKit where to find your wkhtmltopdf:

Rails::Initializer.run do |config|
  require "pdfkit"
  config.middleware.use PDFKit::Middleware
  PDFKit.configure do |config|
    config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'   # <-- the fix
  end
end

Note

The wkhtmltopdf in /usr/bin/wkhtmltopdf is the version you installed with apt-get install wkhtmltopdf and the version in /usr/local/bin/wkhtmltopdf is, as you probably know, the version you installed running the (2) steps.

Important Note

I still got this error when an ActionController::RoutingError (No route matches "...") occurred, e.g. missing a file like image, css, etc. because of broken PDFKit v0.5.4. At the moment I'm fine with v0.5.1.

Posted by Martin Straub to makandra dev (2013-11-04 17:23)