Question

I'm using the gem 'pdfkit' in a Rails app. It is working fine on Heroku, but gets an error on my iMac.

Error:

command failed: "/users/myname/sites/ndeavor2/bin/wkhtmltopdf-amd64"

The application wkhtmltopdf-amd64 is in the folder indicated in the error!

My application.rb has:

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

And I have an initializer called pdfkit.rb

PDFKit.configure do |config|
  config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
end

Thanks for the help!

UPDATE1

I downloaded wkhtmltopdf.app and placed in the same location as the amd64 version.

I changed the pdfkit.rb to:

PDFKit.configure do |config|
  config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s if Rails.env.production?
  config.wkhtmltopdf = Rails.root.join('bin', 'wkhtmltopdf.app').to_s if Rails.env.development?
end

I also put a copy of wkhtmltopdf.app into the applications folder and tried this:

  config.wkhtmltopdf = '/applications/wkhtmltopdf.app' if Rails.env.development?

I'm getting this error:

command failed: 
Was it helpful?

Solution

wkhtmltopdf-amd64 is a binary for amd64 platform computers. Unless you iMac has an AMD chip under the hood, that's why it's failing. You want the OS X binary here: http://code.google.com/p/wkhtmltopdf/downloads/detail?name=wkhtmltopdf-0.9.9-OS-X.i368

Heroku must run on AMD64 or their virtualization is an AMD architecture. That should be why it works on Heroku.

Update: You may want the full app for OS X from here: http://code.google.com/p/wkhtmltopdf/downloads/detail?name=wkhtmltopdf.dmg

Not sure how you installed wkhtmltopdf, so don't know which is appropriate for your setup.

UPDATE!!!

If you download the wkhtmltopdf-0.9.9-OS-X.i368 binary, you can rename it to just wkhtmltopdf:

mv wkhtmltopdf-0.9.9-OS-X.i368 wkhtmltopdf

then you need to make it executable:

chmod 775 wkhtmltopdf

You can then test that it runs with:

./wkhtmltopdf

You should see the help/usage info.

If you downloaded the .dmg file, it is a packaged app, but to call it from a program you will have to give the path to the executable which is:

wkhtmltopdf.app/Contents/MacOS/wkhtmltopdf

That is a relative path (note no slash before the wkhtmltopdf.app) so treat accordingly. The .dmg version is at .11 vs .09 for the binary. Don't know the difference though, you'd have to check the docs.

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