Question

Error:

RuntimeError in BillsController#printing

Failed to execute:
"/usr/local/bin/wkhtmltopdf" -q        "file:////var/folders/j5/2wx0qdjj7kl7vbvq3m2z4rj00000gn/T/wicked_pdf20130213-41259-x9dcb5.html" "/var/folders/j5/2wx0qdjj7kl7vbvq3m2z4rj00000gn/T/wicked_pdf_generated_file20130213-41259-mg4iqp.pdf" 
Error: PDF could not be generated!

BillsController:

  # GET /bills
  # GET /bills.json
  def print
    respond_to do |format|
      format.html 
      format.pdf do
        render :pdf => "rechnung_id",
               :layout => "printing.pdf",
               :show_as_html => params[:debug]
      end
    end
  end

as views I created a printing.html.erb and a printing.pdf.erb - and tried both.

I've installed wkhtmltopdf as binary and as gem. When I try to use the gem (commenting out the line:

WickedPdf.config = { :exe_path => '/usr/local/bin/wkhtmltopdf'}

something seems to crash and nothing happens.. When I use the binary, I get the error displayed on top. The versions of my gems are: wicked_pdf (0.9.4) and wkhtmltopdf-binary (0.9.9.1).

I was searching for help - that's what I already tried:

  1. "bundle update" and "bundle install"
  2. installed wkhtmltopdf in version 9.9
  3. added "Mime::Type.register "application/pdf", :pdf"

EDIT: If I use the terminal and enter "wkhtmltopdf www.myHomepage.info myhomepage.pdf" it works fine. "which wkhtmltopdf" gives me the path "/usr/bin/wkhtmltopdf", but if I want to use with one, it's opening "wkhtmltopdf_darwin_386" and the website freezes..

Was it helpful?

Solution

now i solved the problem.

I changed my controller method to:

 def printing
    @bills = Bill.find(params[:id])

    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "bill_#{@bills.id}",
               :wkhtmltopdf => '/usr/bin/wkhtmltopdf',
               :template => '/bills/printing.pdf.erb',
               :disposition => "inline"
               #:save_to_file => Rails.root.join('pdf', "rechnung_#{@bills.id}.pdf")
      end
    end
  end

and i had to remove WickedPDF as middleware in the application.rb:

require 'wicked_pdf'
config.middleware.use WickedPdf::Middleware, {}

now it's working as expected.

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