Rails: wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown)
Asked Answered
S

6

11

I am using Ubuntu 11.04 to develop an app in Ruby on Rails. In the app I need to generate pdf documents. So I am using the wicked_pdf and wkhtmltopdf-binary gems.

In the development environment in my system everything is working fine. But once I deployed the app in production on CentOS 5.6 using Phusion Passenger, when I try to generate pdfs on the fly its giving me the following error:

RuntimeError (Location of wkhtmltopdf unknown)

I am using Ruby1.9.2.p136 Rails 3.1.1

Any help will be much appreciated....Thanks.

Sheers answered 11/10, 2011 at 9:29 Comment(0)
C
11

do you use static wkhtmltopdf binary? i downloaded it here and extraced it to /path/to/rails_app/bin

and add it to rails like this:

#config/initializers/wicked_pdf.rb
WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s,
}
Contractive answered 11/10, 2011 at 10:49 Comment(1)
Changed from i386 to amd64 and this worked for Heroku as well.Nagari
E
12

An alternative is to install the binary via the Gemfile.

Just add the following line to your production group:

gem 'wkhtmltopdf-binary'

That should add binary support for linux-i386, amd64, and darwin.

And then run

bundle install --without development test

to install the gem in a production environment. After which, you just restart your server.

That's all.

I hope this helps

Exhilaration answered 27/12, 2013 at 17:11 Comment(0)
C
11

do you use static wkhtmltopdf binary? i downloaded it here and extraced it to /path/to/rails_app/bin

and add it to rails like this:

#config/initializers/wicked_pdf.rb
WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s,
}
Contractive answered 11/10, 2011 at 10:49 Comment(1)
Changed from i386 to amd64 and this worked for Heroku as well.Nagari
C
8

for mac os - x you should install wkhtmltopdf by homebrew

$ brew tap homebrew/boneyard # the wkhtmltopdf formula is now inactive but still available in the boneyard repository 
$ brew install wkhtmltopdf
Cinquefoil answered 30/8, 2012 at 16:41 Comment(2)
It's not available anymore: Error: No available formula for wkhtmltopdfGaelan
try again but first install boneyard: $ brew tap homebrew/boneyard the brew formular wkhtmltopdf is inactive but still available under the boneyard repoCinquefoil
G
4

Solution for OS X Yosemite

To get it working on Mac OS X 10.10 (Yosemite), install the wkhtmltopdf-binary gem and then put it in your config/initializers/wicked_pdf.rb:

module WickedPdfHelper
  if Rails.env.development?
    if RbConfig::CONFIG['host_os'] =~ /linux/
      executable = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'wkhtmltopdf_linux_x64' : 'wkhtmltopdf_linux_386'
    elsif RbConfig::CONFIG['host_os'] =~ /darwin/
      executable = 'wkhtmltopdf_darwin_386'
    else
      raise 'Invalid platform. Must be running linux or intel-based Mac OS.'
    end

    WickedPdf.config = { exe_path: "#{Gem.bin_path('wkhtmltopdf-binary').match(/(.+)\/.+/).captures.first}/#{executable}" }
  end
end

Ps.: This solution will work on Linux too.

Gaelan answered 27/10, 2014 at 4:31 Comment(3)
Great! This worked for me. Do you any idea why this is now needed?Elwaine
@Elwaine I have no idea. But I'd like to know as well.Gaelan
For mac osx, same way that @Contractive noticed, just you should set path where your binary file is placed, and also put right name, for example: Rails.root.join('/usr/local/bin', 'wkhtmltopdf').to_s,Boddie
W
1

MAC OSX:

brew install wkhtmltopdf

this will let you to install

brew install Caskroom/cask/wkhtmltopdf

then in config/initializers/wicked_pdf.rb

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}
Wellmannered answered 10/2, 2017 at 10:43 Comment(0)
R
0

Just had a similar problem.

As stated in readme, I created an initializer with:

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}
Rentfree answered 16/9, 2015 at 7:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.