0

Locally It works without any error but when I try to generate the PDF on the server it throws:

 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

Here's what's on 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

And in my Gemfile

gem 'wicked_pdf', '~> 1.1'
gem 'wkhtmltopdf-binary', '~> 0.12.3.1'
Bibin Joseph
  • 51
  • 2
  • 8
  • Runtime here means the 3rd party libs are not installed, that is what I think. This particular gem depends on C libraries. Try to generate a PDF by hand from your console and tell what errors will you meet then – seethrough Jun 02 '18 at 11:17
  • wkhtmltopdf http://www.google.com google.pdf working fine on the server. – Bibin Joseph Jun 02 '18 at 11:22

2 Answers2

1

Looks like the wkhtmltopdf command is not in the PATH, you can fix this by changing the WickedPdf.config to

WickedPdf.config = {
  exe_path: Rails.env.production? ? '/path/to/bin/wkhtmltopdf' : '/usr/local/bin/wkhtmltopdf'
}
Samuel G. P.
  • 3,004
  • 2
  • 29
  • 36
Rajesh V
  • 146
  • 4
0

When I downgrade the version of wkhtmltopdf to 0.9.9 in the server worked for me

Bibin Joseph
  • 51
  • 2
  • 8