Wkhtmltopdf RuntimeError (Location of wkhtmltopdf unknown)

I am using Ubuntu 11.04 to develop an application in Ruby on Rails. In the application I need to create pdf documents. Therefore, I use wicked_pdf and wkhtmltopdf-binary gems.

In the development environment, everything is working fine on my system. But as soon as I deployed the application in production on CentOS 5.6 using Phusion Passenger, when I try to generate PDF files on the fly, it gives me the following error:

RuntimeError (Location of wkhtmltopdf unknown)

I am using Ruby1.9.2.p136 Rails 3.1.1

Any help would be greatly appreciated .... Thank you.

+6
source share
6 answers

Are you using static wkhtmltopdf binary? I downloaded it here and added it to /path/to/rails_app/bin

and add it to the rails:

 #config/initializers/wicked_pdf.rb WickedPdf.config = { :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s, } 
+9
source

An alternative is to install a binary file through a gemfile.

Just add the following line:

 gem 'wkhtmltopdf-binary' 

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

+10
source

for mac os - x you must install wkhtmltopdf homebrew

 $ brew tap homebrew/boneyard # the wkhtmltopdf formula is now inactive but still available in the boneyard repository $ brew install wkhtmltopdf 
+8
source

Solution for OS X Yosemite

To make it work 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 as well.

+4
source

We had a similar problem.

As stated in readme , I created an initializer with:

 WickedPdf.config = { exe_path: '/usr/local/bin/wkhtmltopdf' } 
0
source

MAC OSX:

 brew install wkhtmltopdf 

this will allow you to set

 brew install Caskroom/cask/wkhtmltopdf 

then in config/initializers/wicked_pdf.rb

 WickedPdf.config = { exe_path: '/usr/local/bin/wkhtmltopdf' } 
0
source

Source: https://habr.com/ru/post/899038/


All Articles