This was a real head scratcher for me.
I was able to create PDFs without problem in Rails/WEBrick. When I changed to Apache I got the message:
no wkhtmltopdf executable found at please install wkhtmltopdf
Clearly,
gem 'pdfkit'
gem 'wkhtmltopdf-binary'
were in Gemfile and (correctly) installed or things would not work in WEBrick. Searching the web I found this: https://github.com/pdfkit/pdfkit/issues/123
That led me to the answer: Something in the environment for PDFKit or wkhtmltopdf-binary was different between WEBRick and Apache.
I modified the suggestion in https://github.com/pdfkit/pdfkit/issues/123 and created an initializer, ~/config/initializers/pdfkit.rb
# See https://github.com/pdfkit/pdfkit/issues/123
# This should resolve a problem where PDFKit works with WEBrick but not under Apache
require 'rbconfig'
PDFKit.configure do |config|
# See ~/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf
suffix = case RbConfig::CONFIG['host_os']
when /linux/
(RbConfig::CONFIG['host_cpu'] == 'x86_64') ? 'linux_amd64' : 'linux_x86'
when /darwin/
'darwin_x86'
else
raise "Invalid platform. Must be running on linux or intel-based Mac OS."
end
prefix = File.join(Rails.root, '.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf').to_s
config.wkhtmltopdf = "#{prefix}_#{suffix}"
end
I don't like hard coding '.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/wkhtmltopdf-binary-0.12.3.1/bin/wkhtmltopdf' in the code above.
I'd love a suggestion as to how to generate the name on the right hand side of the config.wkhtmltopdf= .