[英]wkhtmltopdf with wicked_pdf issue?
我正在使用 wkhtmltopdf(0.10.0 rc2) 和 wicked_pdf(0.9.9) 來生成 pdf 報告。 運行時出現以下錯誤。
RuntimeError (Error: Failed to execute:
["/usr/bin/wkhtmltopdf", "-q", "--page-size", "A4", "--margin-top", "5", "--margin-bottom", "10", "--margin-left", "5", "--margin-right", "5", "file:////tmp/[\"wicked_pdf\", \".html\"]21873-0", "/tmp/[\"wicked_pdf_generated_file\", \".pdf\"]21873-0"]
Error: PDF could not be generated!
Command Error: Error: Failed loading page file:////tmp/["wicked_pdf", ".html"]21873-0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
)
我的控制器是:
render :pdf => "#{@note_name}",:layout => '/layouts/pdf_template.html.erb', :template=>'pdf/financial/maintenance_exp/maintenance_exp_pdf.html.erb'
任何幫助,將不勝感激。
僅供參考:當我這樣做時 :show_as_html=>true 它不會拋出任何錯誤。它在瀏覽器中呈現 html。
我遇到了同樣的錯誤,並按照此處的說明進行了修復
https://github.com/mileszs/wicked_pdf/issues/157
即我通過將gemfile
條目更改為gemfile
來切換到 gem 的臨時修復:
gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
但請注意,在我的情況下,問題是 Windows 上的文件位置具有 file:// 而不是 file:/// - 所以它可能對你沒有幫助。 另一方面,這是相同的錯誤消息,所以也許值得一試。
類似的錯誤,我試圖使用WickedPdf.new.pdf_from_html_file
我最終使用WickedPdf.new.pdf_from_string
和以下幫助程序來生成呈現的 html 字符串:
def pdf_html
ApplicationController.renderer.new.render(
template: 'purchase_orders/pdf.html.erb',
layout: 'layouts/pdf_layout.html.erb',
locals: { abc: 'xyz' },
formats: [:html]
)
end
顯然假設 ApplicationController 存在
我的導軌版本: 6.0.1
可能有助於其他搜索類似錯誤。
為此,這不是一個解決方案,但它可能會有所幫助:wkhtmltopdf是一個實驗,這是一個錯誤,並且不再受支持。 如果您要使用免費工具,那么我建議您使用:phantomjs。 該工具還可以生成pdf: http : //phantomjs.org/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.