2

I would like to use PDFKit in my Rails 3 application on Windows.

I installed wkhtmltopdf and the pdfkit gem.

Here is the code that I use to create the PDF:

class JobsController < ApplicationController
  def create_pdf_invoice
    kit = PDFKit.new("<h1>Hello</h1><p>This is PDF!!!</p>", :page_size => "A4")
    file = kit.to_file("my_first_pdf")   # Error issued here!!
    ...
  end
end

I got the following error:

Errno::EACCES in JobsController#create_pdf_invoice

Permission denied - "c:\Program Files\wkhtmltopdf" "--page-size" "A4" 
                    "--margin-top" "0.75in" "--margin-right" "0.75in" 
                    "--margin-bottom" "0.75in" "--margin-left" "0.75in" 
                    "--encoding" "UTF-8" "--quiet" "-" "my_first_pdf"

Any ideas ?

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Misha Moroshko
  • 166,356
  • 226
  • 505
  • 746

1 Answers1

13

You will get that error if you point to a folder and not the actual file (.exe)

I got PDFkit to run on windows like this:

  PDFKit.configure do |config|
    config.wkhtmltopdf = 'C:\wkhtmltopdf\wkhtmltopdf.exe'
  end
David Barlow
  • 4,914
  • 1
  • 28
  • 24
  • Thanks a lot! Now it works. I wonder if you could help me also with this one: http://stackoverflow.com/questions/5177074/rails-3-pdfkit-how-to-print-a-view-to-pdf. Many thanks! – Misha Moroshko Mar 03 '11 at 05:39