简体   繁体   中英

wkhtmltopdf with wicked_pdf issue?

I am using wkhtmltopdf(0.10.0 rc2) and wicked_pdf(0.9.9) for generating pdf report. While running i got the following error.

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)
)

my controller are:

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

Any help would be appreciated.

FYI:when I do :show_as_html=>true its not throwing any error.its rendering the html in browser.

I was getting the same error and fixed it by following directions here

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

Namely I switched to temporary fix of gem by changing gemfile entry to:

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

But note that in my case the issue was file locations on windows having file:// instead of file:/// -- so it may not help you. On the other hand, it was the same error message so maybe worth a shot.

Similar error, i was trying to use WickedPdf.new.pdf_from_html_file

I ended up using WickedPdf.new.pdf_from_string with following helper to generate rendered html string:

  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

Obviously assumes ApplicationController is present

My rails version: 6.0.1

Might help other searching for similar errors.

Not a solution, for this, but maybe it helps: wkhtmltopdf was an experiment, that was a mistake and it's no longer supported. If you want use a free tool, than i recommend for you: phantomjs. This tool can also generate pdf: http://phantomjs.org/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM