wicked_pdf无法在生产服务器中运行

时间:2018-06-02 10:22:01

标签: ruby-on-rails ruby-on-rails-3 wkhtmltopdf wicked-pdf wkhtmltopdf-binary

本地它没有任何错误但是当我尝试在服务器上生成PDF时它会抛出:

 RuntimeError (Failed to execute:
    ["/usr/local/bin/wkhtmltopdf", "-q", "file:////tmp/wicked_pdf20180531-994-1x8fbfn.html", "/tmp/wicked_pdf_generated_file20180531-994-1vidmtk.pdf"]
    Error: PDF could not be generated!
Command Error: /usr/bin/env: ruby: No such file or directory

这是 my_controller 上的内容。

pdf=WickedPdf.new.pdf_from_string(render_to_string('disc_bill',:layout=>false))
  save_file = Rails.root.join("public","bill.pdf")
  File.open(save_file, 'wb') do |file|
    file << pdf
  end

在我的 Gemfile

gem 'wicked_pdf', '~> 1.1'
gem 'wkhtmltopdf-binary', '~> 0.12.3.1'

2 个答案:

答案 0 :(得分:1)

看起来wkhtmltopdf命令不在PATH中,您可以通过将WickedPdf.config更改为

来解决此问题
WickedPdf.config = {
  exe_path: (Rails.env.production? ? '/path/to/bin/wkhtmltopdf' : '/usr/local/bin/wkhtmltopdf'
}

答案 1 :(得分:0)

当我将服务器中的wkhtmltopdf版本降级为0.9.9