4
votes

I'm having trouble generating a PDF out of a html page.

I'm using PDFkit. I installed also wkhtmltopdf following the installation instructions. In 'usr/local/bin/' there is now a file called 'wkhtmltopdf'

When I run a pdf with PDFkit, it now gives an error:

command failed: "/usr/local/bin/wkhtmltopdf" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-"

Also, when I try to generate a PDF directly it gives an error:

wkhtmltopdf --page-size A4--quiet http://localhost/invoices/22 -

'/usr/local/bin/wkhtmltopdf: cannot execute binary file'

Any idea of what this could be? This is how the PDFkit config file looks:

PDFKit.configure do |config|
  config.wkhtmltopdf = '/usr/local/bin/wkhtmltopdf'
end
2
When I encountered a similar error it was because the account I was executing under did not have execute permissions on wkhtmltopdf. I wound up doing a chmod on it.ScottJShea
I checked the permissions, but it has all permissions for all users.John
It seems some installation issues. Which version of WKHTMLTOPDF you are using and in which OS?ppant
I am having a similar problem on mac os x lion.Noah Clark

2 Answers

0
votes

You have to give the whole path of executable Like this

The path should look like: C:/usr/local/bin/wkhtmltopdfwkhtmltopdf.exe

try this it works great

0
votes

I've installed wkhtmltopdf on my Mac OSX with homebrew and I'm using the wicked_pdf gem and I was getting similar errors. This might be helpful:

In my rails 3 app I have a file app/config/initializers/wicked_pdf.rb that contains

# brew install wkhtmltopdf
WickedPdf.config = { :exe_path => '/usr/local/bin/wkhtmltopdf'} if Rails.env == 'development'

The worked for me. So you might wanna try:

PDFKit.configure do |config|
  config.wkhtmltopdf = { :exe_path => '/usr/local/bin/wkhtmltopdf' }
end

Also: see the github project page's installation instructions:

https://github.com/mileszs/wicked_pdf