简体   繁体   中英

Rails wicked_pdf works on Heroku and not local

I'm using wicked_pdf to generate PDFs in a Rails 3.2 app.

GEM files:

gem 'wicked_pdf', '0.9.6'
gem 'combine_pdf'
gem 'wkhtmltopdf-binary', '0.9.9.1'

It works great on Heroku, but I get an error on my local MAC:

  Rendered costprojects/viewproject.pdf.erb (536.1ms)
Completed 500 Internal Server Error in 1623ms

    RuntimeError - Failed to execute:
    "/Users/davidburton/.rvm/gems/ruby-1.9.3-p484/bin/wkhtmltopdf" -q      --encoding "UTF-8"   "file:////var/folders/m9/vzbf4tr91yz4ftmkm_n7zr900000gp/T/wicked_pdf20170427-26825-1xrczw0.html" "/var/folders/m9/vzbf4tr91yz4ftmkm_n7zr900000gp/T/wicked_pdf_generated_file20170427-26825-1lyb9ja.pdf" 
    Error: PDF could not be generated!
     Command Error: :
      (gem) wicked_pdf-0.9.6/lib/wicked_pdf.rb:68:in `rescue in pdf_from_string'
      (gem) wicked_pdf-0.9.6/lib/wicked_pdf.rb:72:in `pdf_from_string'
      (gem) wicked_pdf-0.9.6/lib/pdf_helper.rb:63:in `make_pdf'
      (gem) wicked_pdf-0.9.6/lib/pdf_helper.rb:32:in `render_to_string_with_wicked_pdf'

I had the same error before and fixed by following steps.

In config/initializers/wicked_pdf.rb , set config like this :

WickedPdf.config = {
  exe_path: '/usr/local/bin/wkhtmltopdf'
}

Try this in your Gemfile :

gem 'wicked_pdf'
gem 'wkhtmltopdf-binary',       group: [:development]
gem 'wkhtmltopdf-binary-edge',  group: [:production, :staging]

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