views:

336

answers:

2

Hello,

I have setup PDFKit in my Rails 3 application, using RVM (had to manually copy the wkhtmltopdf binary). When I try to render the PDF version of a page, I get this error:

RuntimeError in AgenciesController#show

command failed: ["lib/wkhtmltopdf/wkhtmltopdf", "--disable-smart-shrinking", "--page-size", "Letter", "--margin-top", "0.75in", "--margin-right", "0.75in", "--margin-bottom", "0.75in", "--margin-left", "0.75in", "--encoding", "UTF-8", "--quiet", "\n.......\n", "-"]

The following is in my applicaition.rb:

    config.middleware.use "PDFKit::Middleware"
    PDFKit.configure do |config|
    config.wkhtmltopdf = 'lib/wkhtmltopdf/wkhtmltopdf' 

    end

An ideas why this is happening? how can I fix it?

In the console, I noticed this message:

 (sometimes it will work just to ignore this error with --ignore-load-errors)

Where do I invoke that switch? wkhtmltopdf seems to be working fine on the command line, I can do something like "./wkhtmltopdf http://www.google.com google.pdf" and generate a PDF.

Thanks for your help,

Peter

+1  A: 

Judging from the source code, you can set options on pdfkit. I think the following will work:

PDFKit.configure do |config|
  config.default_options[:ignore_load_errors] = true
end

(I didn't test it though)

troelskn
That worked so that the app doesn't crash when I load a page with .pdf. The PDF page, however, is getting rendered blank. What could be causing that?
futureshocked
I'm guessing that `wkhtmltopdf` fails. Not sure what to do about that though.
troelskn
A: 

I used this hack.

config.wkhtmltopdf = 'which wkhtmltopdf'.gsub(/\n/, '')

that is (backtick)which wkhtmltopdf(/backtick)

the which command returns a new line at the end.

Benjamin Lewis