ruby-on-rails - wicked_pdf 在生产服务器中不起作用
问题描述
在本地它可以正常工作,但是当我尝试在服务器上生成 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'
解决方案
看起来 wkhtmltopdf 命令不在 PATH 中,您可以通过将 WickedPdf.config 更改为来解决此问题
WickedPdf.config = {
exe_path: Rails.env.production? ? '/path/to/bin/wkhtmltopdf' : '/usr/local/bin/wkhtmltopdf'
}
推荐阅读
- r - 在 VS Code 中加载 R 扩展之前运行 bash 代码
- azure - 尝试从 Azure DevOps 导出已完成的测试用例/测试运行/测试步骤和输出
- javascript - ChartJS 版本 3 - 多个折线图的常用图例
- postgresql - 将数据库导入在 Kubernetes 上运行的 Postgres
- docker - 使用模式设置 WORKDIR
- .net - 使用引用的主项目发布测试项目
- javascript - apexcharts somtimes 漂浮在容器上,当我调整窗口大小时它会修复
- javascript - 使用来自 url 将 React.js 组件注入到静态 HTML 站点?
- javascript - 当可重用映射组件发生更改时更新状态
- php - 导出 woocommerce 产品时删除 HTML 标签