嗨,我对这个宝石真的很生气。
我有一个带有常规响应块的控制器操作:
respond_to do |format|
format.html
format.pdf do
render pdf: "Print",
template: "claims/print.html.erb"
layout: "print_claim.pdf"
end
end
这很有效,但是,现在我需要为某些特定的 pdf(如信封)使用不同的页面大小。 所以我正在尝试将下一个值添加到初始化文件夹中的 wicked_pdf.config 中或respond_to块中,例如:
respond_to do |format|
format.html
format.pdf do
render pdf: "Print",
template: "claims/print.html.erb"
layout: "print_claim.pdf",
page_size: 'Letter',
page_width: '10in',
page_height: '6in'
end
end
或在初始化文件中,例如:
WickedPdf.config = {
page_size: 'Letter',
page_height: '10in',
page_width: '10in',
exe_path: File.join(Rails.root,"bin","wkhtmltopdf-to-chrome")
}
但这会返回错误,例如:
Failed to execute: ["/bin/wkhtmltopdf-to-chrome", "-q", "--page-size", "A6", "file:////tmp/wicked_pdf20181224-5644-m4s0rw.html", "/tmp/wicked_pdf_generated_file20181224-5644-3t6s75.pdf"] Error: PDF could not be generated! Command Error: FATAL: expect 3 arguments and got: 5
所以,最后我设法通过commenting out
初始化文件的全部内容来解决此问题wicked_pdf.rb
。并添加到项目gem 'wkhtmltopdf-binary'
.所以现在向块添加更多参数respond_to效果很好。