2013-02-13 74 views
3

錯誤:「錯誤:無法生成PDF!」與WickedPDF

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 

的觀點我創建了一個printing.html.erb和printing.pdf.erb - 並試圖兩者。

我已經安裝了wkhtmltopdf作爲二進制文件和寶石。當我嘗試使用寶石(註釋掉行:

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

東西似乎崩潰,沒有任何反應.. 當我使用二進制,我頂得上顯示的錯誤 我的寶石版本分別是: wicked_pdf(0.9.4) 和wkhtmltopdf二進制(0.9.9.1)

我正在尋找的幫助 - 這就是我已經嘗試過:

  1. 「捆綁更新」 和「捆綁安裝「
  2. 在9.9版
  3. 安裝wkhtmltopdf加入 「啞劇:: Type.register 」應用程序/ PDF「:PDF」

編輯: 如果我使用的終端,輸入「wkhtmltopdf www.myHomepage。 info myhomepage.pdf「它工作正常。 「其中wkhtmltopdf」給我的路徑「/ usr/bin/wkhtmltopdf」,但如果我想用一個,它打開「wkhtmltopdf_darwin_386」和網站凍結..

回答

1

現在我解決了這個問題。

我改變了我的控制方法:

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 

,我不得不在application.rb中刪除WickedPDF中間件:

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

現在它工作正常。