Question

I am trying to create a pdf using wicked-pdf from Ruby On Rails. It works great in development mode, but when I deploy in production I get the error:

wkhtmltopdf is not executable

I have the wkhtmltopdf executable located at:

rails_root/bin/wkhtmltopdf-i386

Warbler is setup to include the bin folder in the war:

config.includes = FileList["classes/*","bin/*"]

I have wicked pdf configured to find the bin in the correct spot:

WickedPdf.config = {
  :exe_path => Rails.root.join('bin', 'wkhtmltopdf-i386').to_s
}

I run warbler and then deploy the war on jBoss application server. When I try to generate a PDF I get the error about it not being executable. It runs fine in development mode - not in a war.

The permissions on the binary should be fine:

-rwxr-xr-x  1 username group 11446024 Apr  3 11:40 wkhtmltopdf-i386

Instead of manually including the wkhtmltopdf binary, I tried using wkhtmltopdf-binary gem. This too worked fine in development mode, but Wicked PDF can't find the binary in production.

Update: I changed the wicked-pdf config to point to the binary provided by 'wkhtmltopdf-binary' gem when in production mode. It also is getting wkhtmltopdf is not executable error. The path ends up being: jboss-5.1.0.GA/server/default/tmp/3j001-3g0fg5-hf2xi49o-1-hf2xiuld-9q/myrailsapp.war/WEB-INF/gems/gems/wkhtmltopdf-binary-0.9.9.1/bin/wkhtmltopdf_linux_386

Was it helpful?

Solution

Do you install wkhtmltopdf separately or allow your gem file to install it?

I'd do the following:

gem 'wicked_pdf', '~> 0.9.10'
gem 'wkhtmltopdf-binary', '~> 0.9.9'

and then set the config:

WickedPdf.config = {
  exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf_linux_386"
}

This bit #{Gem.loaded_specs['wkhtmltopdf-binary'].version} queries your gems to find the current version if you were to ever change the version of the gem, your prod server would still be able to find the proper folder.

OTHER TIPS

I faced this same issue when working with a Rails 5.2.3 application on an Ubuntu 18.04.

The error displayed is this:

Gem::Exception: can't find executable wkhtmltopdf for gem wkhtmltopdf-binary. wkhtmltopdf-binary is not currently included in the bundle, perhaps you meant to add it to your Gemfile?

Here's how I solved it:

I simply added the wkhtmltopdf-binary gem to the production group which already had the wkhtmltopdf-heroku in the Gemfile.

group :production do
 gem 'wkhtmltopdf-heroku'
 gem 'wkhtmltopdf-binary'
end

And then installed the gem

bundle install --without development test

If you're running on a production server, please endeavour to install the libxrender1 library, since it's a dependency for wkhtmltopdf (for rendering PDFs), to avoid en error when rendering PDFs.

sudo apt-get install libxrender1

That's all.

I hope this helps

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top