2011-03-28 120 views
0

我安裝了PDFKit和wkhtmltopdf。PDFKit不生成正確PDF

在一個動作我呈現一個簡單的HTML,如:

<html><body><h1>Hello Internet!</h1></body></html> 

當我跑我的.pdf擴展動作它會產生一個錯誤的PDF文件。調試PDFKit我到這些行:

result = IO.popen(invoke, "w+") do |pdf| 
    pdf.puts(@source.to_s) if @source.html? 
    pdf.close_write 
    pdf.gets(nil) 
end 

嗯,這是生成我的PDF在那裏,它使用一個命令行沒有wkhtmltopdf和我的HTML作爲輸入。

使用中,RDebug我發現,調用值:

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-" 

而@ source.to_s是

<html><body><h1>Hello Internet!</h1></body></html> 

好了,我試圖用手像這樣運行命令:

"c:\Program Files\wkhtmltopdf\wkhtmltopdf.exe" "--margin-right" "0.75in" "--page-size" "Letter" "--margin-top" "0.75in" "--margin-bottom" "0.75in" "--encoding" "UTF-8" "--margin-left" "0.75in" "--quiet" "-" "-" <c:\hello_internet.html> correct.pdf 

顯然在hello_internet中有@ source.to_s的內容

運行它會生成正確的pdf。

生成的正確pdf是here,錯誤是here

我不知道這裏可能會出現什麼問題。

謝謝。

+0

也許我錯了!您是否正在嘗試使用pdfkit從沒有使用wkhtmltopdf的HTML源代碼生成pdf? – tommasop 2011-03-28 08:37:55

回答

0

該解決方案非常簡單,並且是PDFKits Github上的bxu689的pull request的對象。