Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No wkhtmltopdf executable found #123

Closed
giacomopiva opened this issue Dec 27, 2011 · 23 comments
Closed

No wkhtmltopdf executable found #123

giacomopiva opened this issue Dec 27, 2011 · 23 comments

Comments

@giacomopiva
Copy link

I'm using rails 3.0.9 and ruby 1.8.7 and I'm getting this error:

No wkhtmltopdf executable found at

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

The executable is installed and accessible (in the PATH) and it have 755 permissions.

@abelmartin
Copy link

I'm also seeing the same problem on our prod server (Ruby 1.8.7p352, Rails 3.0.10, PDFKit 0.5.2, wkhtmltopdf 0.9.6). I didn't used to have this issue in prod with our Rails 2.3.2 app with wkhtmltopdf 0.9.6, but we recently upgraded.

What's odd is that if I run a simple HTML to PDF conversion from the rails console (in production environment), it works just fine.

Could this error message be masking another error?

-a

@stuart
Copy link

stuart commented Jan 4, 2012

Also seeing this issue on Rails 2.3.10, PDFKit 0.5.2 and wkhtmltopdf 0.9.6.
PDFKit.configuration.wkhtmltopdf is not set in the running application. It is set correctly when I use PDFKit in the console.

Found the problem was with line 20 of configuration.rb

    @wkhtmltopdf ||= (defined?(Bundler::GemfileError) ? `bundle exec which wkhtmltopdf` : `which wkhtmltopdf`).chomp

This was giving a non existent path with bundle exec. 
The workaround was to set the path in an initializer like so:

PDFKit.configure do |config|
  config.wkhtmltopdf = `which wkhtmltopdf`
end

@abelmartin
Copy link

Ha!

I was just about to post a similar solution. Mine's more static, but ultimately the same thing:

if Rails.env.production?

  PDFKit.configure do |config|
    config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
  end

end

...in my config/initializers/pdfkit.rb :) I prefer your solution @stuart since it works in all environments without a messy conditional.

-a

@giacomopiva
Copy link
Author

Stuart hit the problem.
In my case the problem is the production environment has many version of bundle installed, and the bundle for ruby 1.8.7 the executable name is bundle187, so I changed the line with:

@wkhtmltopdf ||= (defined?(Bundler::GemfileError) ?bundle187 exec which wkhtmltopdf:which wkhtmltopdf`).chomp

Now it works in my case.

@vcabana
Copy link

vcabana commented Apr 16, 2012

Good day to all!

I have tried the solutions you provided above and still I'm experiencing the same issue. May you please help me fix this issue(No wkhtmltopdf executable found)?

FYI, I'm using windows pc and have successfully installed the wkhtmltopdf.

Thanks,

Vic

@tdm00
Copy link
Contributor

tdm00 commented Jun 21, 2012

I'm hitting this same problem. I have a user setup on my Linux system named deploy, with RVM and Ruby 1.9.3 install there. I have the gem 'wkhtmltopdf-binary' and gem 'pdfkit' in my Gemfile, both are installed on the system. When I attempt to render the HTML file to a PDF I'm told:


> > Please install wkhtmltopdf - https://github.com/jdpace/PDFKit/wiki/Installing-WKHTMLTOPDF):
> >   pdfkit (0.5.2) lib/pdfkit/pdfkit.rb:29:in `initialize'
> >   pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in`new'
> >   pdfkit (0.5.2) lib/pdfkit/middleware.rb:21:in `call'
> > 
> > ```
> > If I type `which wkhtmltopdf` then I'm told:
> > ```
> > 
> > /home/deploy/.rvm/gems/ruby-1.9.3-p194/bin/wkhtmltopdf
> > 
> > ```
> > ```

@vcabana
Copy link

vcabana commented Jun 21, 2012

Good day, Troy!

Please see below for the setup process I have implemented on my windows PC to fix the above issue.

PDF KIT

  1. Install wkhtmltopdf.
    a. For Windows
    i) Download wkhtmltopdf-0.9.9-installer.exe .
    ii) Install it to this directory C:\wkhtmltopdf to avoid permission issue of the app when integrating it to PDF KIT.
    b. For Mac
   curl -O http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-OS-X.i368
  mv wkhtmltopdf-0.9.9-OS-X.i368 /usr/local/bin/wkhtmltopdf
  chmod +x /usr/local/bin/wkhtmltopdf
c.  For Mac with Homebrew

 brew install WKHTMLTOPDF

d.  Linux(Arch Linux)

 # Install the wkhtmltopdf package from community
 sudo pacman -Sy wkhtmltopdf

e.  Linux(Ubuntu)

 # Install the wkhtmltopdf package
 sudo apt-get install wkhtmltopdf
 or
 # first, installing dependencies
 sudo aptitude install openssl build-essential xorg libssl-dev

 # for 64bits OS
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

# for 32bits OS
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-i386.tar.bz2 
tar xvjf wkhtmltopdf-0.9.9-static-i386.tar.bz2
mv wkhtmltopdf-i386 /usr/local/bin/wkhtmltopdf
chmod +x /usr/local/bin/wkhtmltopdf

 f. Linux (Gentoo on Rackspace Cloud)
 # search for the following first using emerge --search <files here> I've just put the ones i needed.
 # Note that we may find an easier way later, but wkhtmltopdf responded each time needing these pkgs.
   sudo emerge libXext app-admin/eselect-fontconfig x11-libs/libXrender

 # for 64bits OS
 wget http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2 
 tar xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
 mv wkhtmltopdf-amd64 /usr/local/bin/wkhtmltopdf
 chmod +x /usr/local/bin/wkhtmltopdf
  1. Write gem ‘pdfkit’ in the Gemfile. Also, the gem ‘wkhtmltopdf-binary’ for mac + linux i386 OS.
  2. Run bundle install
  3. Write the following lines in the application.rb file:

Middle ware for PDF Kit

config.middleware.use 'PDFKit::Middleware'
4. Create a file named pdfkit.rb in the config/initializers and write the following lines:

PDF Kit

PDFKit.configure do |config|
config.wkhtmltopdf = 'C:/wkhtmltopdf/wkhtmltopdf.exe'
config.default_options = {
:page_size => 'Legal',
:print_media_type => true

config.root_url = "http://localhost" # Use only if your external hostname is unavailable on the server.

}
End

  1. Create a file named pdfkit_asset.rb in the config/initializers and write the following lines:

ActionController::Base.asset_host = Proc.new { |source, request|
if request.env["REQUEST_PATH"].include? ".pdf"
"file://#{Rails.root.join('public')}"
else
"#{request.protocol}#{request.host_with_port}"
end
}

  1. In application.html file, add :media property. See example below.
    <%= stylesheet_link_tag 'application', :media => "all" %>
  2. In your page, just append .pdf to test if it is working or specify a link to convert a page to PDF. See example below.

References: https://github.com/pdfkit/PDFKit
https://github.com/pdfkit/pdfkit/wiki/Installing-WKHTMLTOPDF
http://railscasts.com/episodes/220-pdfkit
http://code.google.com/p/wkhtmltopdf/

I hope the above process will fix the issue you have on your Linux system.

Regards,

Vic Abana

@tdm00
Copy link
Contributor

tdm00 commented Jun 21, 2012

@viclnp that helped me get a little further. I've removed the wkhtmltopdf-executable gem from my Gemfile, then re-deployed to my server via Capistrano. However now I'm getting this message when trying to generate a PDF:

RuntimeError (command failed: "/home/deploy/apps/myapp/shared/bundle/ruby/1.9.1/bin/wkhtmltopdf" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-right" "0.75in" "--margin-bottom" "0.75in" "--margin-left" "0.75in" "--encoding" "UTF-8" "--print-media-type" "--quiet" "-" "-"):

Not sure why that's still show up there, I thought removing it from my Gemfile would remove it. If I do
/home/deploy/apps/myapp/shared/bundle/ruby/1.9.1/bin/wkhtmltopdf --version it reports the version number correctly.

@vcabana
Copy link

vcabana commented Jun 22, 2012

@talltroym - On your local PC, please generate pdf using your terminal? If the same issue occurs, then can you move the directory of your wktmltopdf to your local drive or to your desktop then change the directory of the config.wkhtmltopdf you defined in the pdfkit.rb from config/initializers.

Hope that helps and will fix the issue.

Vic Abana

@tdm00
Copy link
Contributor

tdm00 commented Jun 22, 2012

@viclnp - thanks for the replies. I setup a new virtual server and I was able to configure this to work. I think the problem is on my production server in the Gemfile I had the "wkhtmltopdf-executable" in the Gemfile, so it installed there. Now I've removed it from the Gemfile, but that didn't remove the gem from the system (I'm using Capistrano). I'll either figure out how to remove that one gem in that shared directory, or wipe out the app and re-deploy it without that gem, but having the wkhtmltopdf installed on the server like your directions show. This is what I did on the virtual server to get it to work.

@vcabana
Copy link

vcabana commented Jun 22, 2012

@talltroym - You are welcome! :)

@Blakey
Copy link

Blakey commented Jan 27, 2013

Hi,

I am having real trouble getting PDFkit to work with ruby on Windows 7 system.

I am trying to follow the steps above but have no idea what to do at step 4:

 "Create a file named pdfkit.rb in the config/initializers and write the following lines:

PDF Kit

PDFKit.configure do |config|
config.wkhtmltopdf = 'C:/wkhtmltopdf/wkhtmltopdf.exe'
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
config.root_url = "http://localhost" # Use only if your external hostname is unavailable on the server.

}
End"

Where is config/initializers ?? i cannot find it anywhere.

Appreciate any help.

Thanks

@tdm00
Copy link
Contributor

tdm00 commented Jan 27, 2013

That should be in the root of your Ruby on Rails app structure, config folder then initializers folder under that

On Jan 26, 2013, at 7:27 PM, Blakey notifications@github.com wrote:

Hi,

I am having real trouble getting PDFkit to work with ruby on Windows 7 system.

I am trying to follow the steps above but have no idea what to do at step 4:

"Create a file named pdfkit.rb in the config/initializers and write the following lines:
PDF Kit

PDFKit.configure do |config|
config.wkhtmltopdf = 'C:/wkhtmltopdf/wkhtmltopdf.exe'
config.default_options = {
:page_size => 'Legal',
:print_media_type => true
config.root_url = "http://localhost" # Use only if your external hostname is unavailable on the server.

}
End"

Where is config/initializers ?? i cannot find it anywhere.

Appreciate any help.

Thanks


Reply to this email directly or view it on GitHub.

@Blakey
Copy link

Blakey commented Jan 27, 2013

OK that explains why i cannot find it. I am not running rails (Not ready for building a web app yet - just trying to speed my life up a bit with a nifty bit of programming). Is PDFKit not going to work without rails? Or do i just need to update the config elsewhere? Sorry - pretty new to all of this!

@sodabrew
Copy link

You don't need to be in Rails. You just need to run the "PDFKit.configure do |config| ... " block from your code prior to using PDFkit.

@Blakey
Copy link

Blakey commented Jan 27, 2013

Thanks guys. I have tried running from my code with no success. I'm going to start from scratch again and will hopefully see what has gone wrong. Will report back soon :)

Update: I deleted, re-installed everything and used above code and it wokrs perfectly now.

Thanks sodabrew and talltroym

@ghost
Copy link

ghost commented Jun 7, 2016

Hi folks, sorry to resurrect an old thread. I have the same issue that Blakey had, but which file do I paste the PDFKit.configure do stuff into?

Cheers!

@vcabana
Copy link

vcabana commented Jul 14, 2016

Just read this @mcljot. Is this resolved? Thanks.

@ghost
Copy link

ghost commented Jul 14, 2016

Hey, more or less resolved – through another method! Thanks!

From: Vic Abana [mailto:notifications@github.com]
Sent: 14 July 2016 13:20
To: pdfkit/pdfkit
Cc: McLeod, Alex [TYCO GBS - Cork]; Mention
Subject: Re: [pdfkit/pdfkit] No wkhtmltopdf executable found (#123)

Just read this @mcljothttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_mcljot&d=CwMCaQ&c=0YGvTs3tT-VMy8_v51yLDw&r=ucoheL-CAyLyDRiVDhh6tGC4vjlKuq8AWAspOX8m5cM&m=exxMCoH0e_8nKAQHj3VwN8rihx8ZqKD36dWcW9uRNnQ&s=LHV0VPI3unL1rRqB8Z0e_gOYhV7gdUZu_yayAwnZck4&e=. Is this resolved? Thanks.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHubhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_pdfkit_pdfkit_issues_123-23issuecomment-2D232649818&d=CwMCaQ&c=0YGvTs3tT-VMy8_v51yLDw&r=ucoheL-CAyLyDRiVDhh6tGC4vjlKuq8AWAspOX8m5cM&m=exxMCoH0e_8nKAQHj3VwN8rihx8ZqKD36dWcW9uRNnQ&s=DAYBbdmcPd7HRzhwOZ87EDxWWwosdKDoCeUey3MmY40&e=, or mute the threadhttps://urldefense.proofpoint.com/v2/url?u=https-3A__github.com_notifications_unsubscribe_ASwWuO7ITdxdkReSL4PV-5FUKeZuB23-5FQ1ks5qVil7gaJpZM4ACdiJ&d=CwMCaQ&c=0YGvTs3tT-VMy8_v51yLDw&r=ucoheL-CAyLyDRiVDhh6tGC4vjlKuq8AWAspOX8m5cM&m=exxMCoH0e_8nKAQHj3VwN8rihx8ZqKD36dWcW9uRNnQ&s=QLBnC6wfm4ILT02arzmbD4KJNZ-0wZOaX8TjmjDbUvs&e=.


This e-mail contains privileged and confidential information intended for the use of the addressees named above. If you are not the intended recipient of this e-mail, you are hereby notified that you must not disseminate, copy or take any action in respect of any information contained in it. If you have received this e-mail in error, please notify the sender immediately by e-mail and immediately destroy this e-mail and its attachments.

@vcabana
Copy link

vcabana commented Jul 14, 2016

Great to hear @mcljot! 👍

@jarthod
Copy link
Contributor

jarthod commented Jan 19, 2020

Hi, A couple years latter I'm having a similar issue with this line again:

PDFKit::NoExecutableError (No wkhtmltopdf executable found at )

I'm using wkhtmltopdf-binay gem which in my setup provides the gem in:

> `which wkhtmltopdf`
=> "/home/deploy/.rbenv/versions/2.6.4/bin/wkhtmltopdf\n"

But from by Rails console if I do the bundle exec which wkhtmltopdf I get a tons of warning and an error message from bundler, the command doesn't work, returns empty string, and PDFKit fails with the (wrong) error message shown above:

> `bundle exec which wkhtmltopdf`
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:105: warning: already initialized constant Bundler::FileUtils::VERSION
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils/version.rb:4: warning: previous definition of VERSION was here
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:1284: warning: already initialized constant Bundler::FileUtils::Entry_::S_IF_DOOR
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils.rb:1267: warning: previous definition of S_IF_DOOR was here
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:1568: warning: already initialized constant Bundler::FileUtils::Entry_::DIRECTORY_TERM
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils.rb:1547: warning: previous definition of DIRECTORY_TERM was here
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:1626: warning: already initialized constant Bundler::FileUtils::OPT_TABLE
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils.rb:1602: warning: previous definition of OPT_TABLE was here
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:1685: warning: already initialized constant Bundler::FileUtils::LOW_METHODS
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils.rb:1656: warning: previous definition of LOW_METHODS was here
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/fileutils/lib/fileutils.rb:1692: warning: already initialized constant Bundler::FileUtils::METHODS
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.0.2/lib/bundler/vendor/fileutils/lib/fileutils.rb:1663: warning: previous definition of METHODS was here
Traceback (most recent call last):
	9: from /home/deploy/.rbenv/versions/2.6.4/bin/bundle:23:in `<main>'
	8: from /home/deploy/.rbenv/versions/2.6.4/bin/bundle:23:in `load'
	7: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:13:in `<top (required)>'
	6: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:13:in `require_relative'
	5: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:7:in `<top (required)>'
	4: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler.rb:7:in `require_relative'
	3: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/errors.rb:3:in `<top (required)>'
	2: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/errors.rb:20:in `<module:Bundler>'
	1: from /home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/errors.rb:20:in `<class:GemfileError>'
/home/deploy/.rbenv/versions/2.6.4/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/errors.rb:9:in `status_code': Trying to register Bundler::GemfileError for status code 4 but Bundler::GemfileError is already registered (ArgumentError)
=> ""

I'm using bundler v2.0.2.

I see I'm not the first to have the problem and everyone is circumventing the problem with hack and hardcoding the path (eg https://stackoverflow.com/questions/32429977/why-cant-bundler-find-wkhtmltopdf-on-server?rq=1). Isn't it time we fix this?

In my case it seems it was running bundle exec from an ENV already started using bundler (rails c) was causing the problem, and updating rubygems + bundler fixed the problem for me: https://github.com/rubygems/bundler/issues/7484

But PDFKit still provides the wrong error message which doesn't help, also if which wkhtmltopdf works why not use this as a fallback? (or as first option) instead of raising an error?

Something like:

def default_wkhtmltopdf
  return @default_command_path if @default_command_path
  if defined?(Bundler::GemfileError) && File.exists?('Gemfile')
    @default_command_path = `bundle exec which wkhtmltopdf`.chomp
  end
  @default_command_path = `which wkhtmltopdf` if @default_command_path&.empty?
end

What do you think?

@serene
Copy link
Contributor

serene commented Jan 21, 2020

@jarthod Thanks for this suggestion. Can you make a PR with this change?

@jarthod
Copy link
Contributor

jarthod commented Jan 23, 2020

@serene sure, here you go: #460

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants