0

在本地它可以正常工作,但是当我尝试在服务器上生成 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'
4

2 回答 2

1

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

WickedPdf.config = {
  exe_path: Rails.env.production? ? '/path/to/bin/wkhtmltopdf' : '/usr/local/bin/wkhtmltopdf'
}
于 2018-06-04T09:35:15.163 回答
0

当我在服务器中将 wkhtmltopdf 的版本降级到 0.9.9 时,它为我工作

于 2018-06-05T07:10:38.503 回答