"Error: Unable to create PDF!" with WickedPDF

Mistake:

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 print.html.erb and print.pdf.erb - and tried both.

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

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

      

something seems to go wrong and nothing happens. When I use the binary, I get the error displayed at the top. Versions of my gems are wicked_pdf (0.9.4) and wkhtmltopdf-binary (0.9.9.1).

I was looking for help - this is what I already tried:

  • "batch update" and "install package"
  • installed wkhtmltopdf in version 9.9
  • added "Mime :: Type.register" application / pdf ",: pdf"

EDIT: If I use terminal and type "wkhtmltopdf www.myHomepage.info myhomepage.pdf" it works great. "which wkhtmltopdf" gives me the path "/ usr / bin / wkhtmltopdf", but if I want to use it, it will open "wkhtmltopdf_darwin_386" and the site freezes.

+3


source to share


1 answer


now i have 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 application.rb:

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

      

now it works as expected.

+1


source







All Articles