wicked_pdf 无法在生产服务器中工作

问题描述 投票:0回答:3

在本地它可以正常工作,没有任何错误,但是当我尝试在服务器上生成 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'
ruby-on-rails ruby-on-rails-3 wkhtmltopdf wicked-pdf wkhtmltopdf-binary
3个回答
1
投票

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

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

0
投票

当我在对我有用的服务器中将 wkhtmltopdf 版本降级到 0.9.9 时


0
投票

你能解决这个问题吗?我也有同样的问题

© www.soinside.com 2019 - 2024. All rights reserved.