Wicked_pdf错误:无法生成PDF!命令错误:致命:期望3个参数并得到:5

时间:2018-12-24 13:54:10

标签: ruby-on-rails ruby wicked-pdf

嗨,我真的很讨厌这个宝石。

我有一个带有常规响应块的控制器动作:

respond_to do |format|
  format.html
  format.pdf do
    render pdf: "Print",
    template: "claims/print.html.erb"
    layout: "print_claim.pdf"
  end
end

,这很好用,但是,现在我需要对某些特定的pdf(如信封)使用不同的页面大小。因此,我试图将下一个值添加到initialize文件夹中或此处的respond_to块中的wicked_pdf.config中:

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

1 个答案:

答案 0 :(得分:0)

因此,最终我通过commenting out初始化wicked_pdf.rb文件的全部内容来解决了这个问题。 并添加到项目gem 'wkhtmltopdf-binary'中。因此,现在将更多参数添加到response_to块中很好用。

相关问题