【问题标题】:wkhtmltopdf with wicked_pdf issue?wkhtmltopdf 与 wicked_pdf 问题?
【发布时间】:2014-11-19 14:07:32
【问题描述】:

我正在使用 wkhtmltopdf(0.10.0 rc2) 和 wicked_pdf(0.9.9) 来生成 pdf 报告。 运行时出现以下错误。

RuntimeError (Error: Failed to execute:
["/usr/bin/wkhtmltopdf", "-q", "--page-size", "A4", "--margin-top", "5", "--margin-bottom", "10", "--margin-left", "5", "--margin-right", "5", "file:////tmp/[\"wicked_pdf\", \".html\"]21873-0", "/tmp/[\"wicked_pdf_generated_file\", \".pdf\"]21873-0"]
Error: PDF could not be generated!
 Command Error: Error: Failed loading page file:////tmp/["wicked_pdf", ".html"]21873-0 (sometimes it will work just to ignore this error with --load-error-handling ignore)
)

我的控制器是:

render :pdf => "#{@note_name}",:layout => '/layouts/pdf_template.html.erb', :template=>'pdf/financial/maintenance_exp/maintenance_exp_pdf.html.erb'

任何帮助将不胜感激。

仅供参考:当我这样做时 :show_as_html=>真 它没有抛出任何错误。它在浏览器中呈现 html。

【问题讨论】:

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


    【解决方案1】:

    类似的错误,我试图使用WickedPdf.new.pdf_from_html_file

    我最终使用 WickedPdf.new.pdf_from_string 和以下帮助程序来生成呈现的 html 字符串:

      def pdf_html
        ApplicationController.renderer.new.render(
          template: 'purchase_orders/pdf.html.erb',
          layout: 'layouts/pdf_layout.html.erb',
          locals: { abc: 'xyz' },
          formats: [:html]
        )
      end
    

    显然假设 ApplicationController 存在

    我的 Rails 版本:6.0.1

    可能有助于其他人搜索类似的错误。

    【讨论】:

      【解决方案2】:

      我遇到了同样的错误,并按照此处的说明进行了修复

      https://github.com/mileszs/wicked_pdf/issues/157

      也就是说,我通过将gemfile 条目更改为:

      gem 'wicked_pdf', github: 'mileszs/wicked_pdf'
      

      但请注意,在我的情况下,问题是 Windows 上的文件位置具有 file:// 而不是 file:/// - 所以它可能对您没有帮助。另一方面,这是相同的错误消息,因此可能值得一试。

      【讨论】:

      • 这在发布问题时有效,现在不是解决方案(对于仍在搜索此错误的人)请在此处查看我的答案以了解对我有用的方法。
      猜你喜欢
      • 1970-01-01
      • 2015-08-19
      • 2012-11-02
      • 1970-01-01
      • 2012-07-27
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      相关资源
      最近更新 更多