【问题标题】:wicked_pdf not working in production serverwicked_pdf 在生产服务器中不起作用
【发布时间】:2018-06-02 10:22:01
【问题描述】:

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

【问题讨论】:

  • 这里的运行时意味着没有安装第 3 方库,这就是我的想法。这个特定的 gem 依赖于 C 库。尝试从控制台手动生成 PDF,然后告诉您会遇到哪些错误
  • wkhtmltopdf google.com google.pdf 在服务器上工作正常。

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


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-27
      • 1970-01-01
      • 1970-01-01
      • 2016-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多