4

I got pdfkit install and even set up wkhtmltopdf installed as well however I'm getting the following error everytime I try to create a pdf.

PDFKit::NoExecutableError 
No wkhtmltopdf executable found at bundler: command not found: which
Install missing gem executables with `bundle install`
>> Please install wkhtmltopdf - https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF

My Gemfile has the following:

gem 'jquery-rails'
gem 'devise'
gem 'carrierwave'
gem "wkhtmltopdf"
gem 'pdfkit'

And my application.rb has the following entry:

config.middleware.use "PDFKit::Middleware", :print_media_type => true

am I missing something here - I've run a bundle install but still get this error everytime I try to create a pdf. Please help

3 Answers 3

6

You should read Install readme here:

https://github.com/jdpace/PDFKit

so you need to install wkhtmltopdf manualy:

https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF

or like this

gem install wkhtmltopdf-binary

PS

check which wkhtmltopdf

and create new file config/initializers/pdfkit.rb

PDFKit.configure do |config|
  config.wkhtmltopdf = 'PATH/TO/wkhtmltopdf'
end
3
  • 1
    windows? lol :) Download wkht.. from code.google.com/p/wkhtmltopdf/downloads/list and install it. then put your installation path into pdfkit.rb
    – fl00r
    Mar 7, 2012 at 13:24
  • Setting config.wkhtmltopdf to '/opt/rubies/ruby-2.2.4/bin/wkhtmltopdf' worked for me when using AWS elastic beanstalk with gem install wkhtmltopdf. Means I didn't have to set up container commands to install wkhtmltopdf on my ec2 instances ... thanks
    – Mark Kenny
    Jul 5, 2016 at 9:17
  • check that last comment ... I meant gem install wkhtmltopdf-binary
    – Mark Kenny
    Jul 5, 2016 at 9:25
2

Ali,

I don't see you mention which operating system you're on. Fl00r, and I, are both assuming that it's a Linux system, so adjust accordingly. This is what I needed to do to make PDFKit work with wkhtmltopdf for my Rails application running on 64-bit Ubuntu 12.04 LTS.

Remove any reference to wkhtmltopdf or wkhtmltopdf-binary from your Gemfile.

Add only gem 'pdfkit', :require => 'pdfkit' to your Gemfile

In your config/initializers/mime_types.rb file add

Mime::Type.register "application/pdf", :pdf

Remove any config/initializers/pdfkit.rb file

Uninstall the gems from the server that you're running the Rails application on

gem uninstall wkhtmltopdf -a
gem uninstall wkhtmltopdf-binary -a

Download to your server wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2 from the project download site here. There is a bug in the latest suggested download versions that prevent a user from being able to select and copy text from a generated PDF, but this version doesn't have that bug. This issue is referenced at http://code.google.com/p/wkhtmltopdf/issues/detail?id=886

Extract the executable from the tar archive

tar -xvf wkhtmltopdf-0.10.0_rc2-static-amd64.tar.bz2

Move it to the /usr/local/bin/ directory

sudo mv wkhtmltopdf-0.10.0.rc2 /usr/local/bin/

Now setup a symbolic link to the file so it's easy to upgrade at a later point

sudo ln -s /usr/local/bin/wkhtmltopdf-0.10.0.rc2 /usr/local/bin/wkhtmltopdf

Set the permissions on the file

sudo chmod 755 /usr/local/bin/wkhtmltopdf-0.10.0.rc2

After doing all of this, and restarting my server, PDFKit will now use the wkhtmltopdf that I have installed on the server.

Caveat: On one occasion my Rails application started reporting that it couldn't find the wkhtmltopdf executable in the path, not sure why as nothing changed. Restarting the server corrected this issue.

0

None of the above worked for me. I tried the solution posted in here https://github.com/pdfkit/pdfkit/issues/123

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.