mileszs / wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails
http://www.mileszs.com/wicked-pdf-plugin
MIT License
3.54k stars 646 forks source link

not working in production server #743

Open bibinjpalathara opened 6 years ago

bibinjpalathara commented 6 years ago

RunTime Error: PDF could not be generated! Command Error: /usr/bin/env: ruby: No such file or directory wicked pdf

This code works fine locally but in the production environment, it is failing on generate. Log below.

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

when I run the command which wkhtmltopdf gives me /usr/local/bin/wkhtmltopdf

wkhtmltopdf http://www.google.com google.pdf also working fine on the server.

unixmonkey commented 6 years ago

Is the path /usr/local/bin/wkhtmltopdf on the production server, or locally?

It looks to me like the binary may actually be a binstub. These are sometimes little Ruby scripts that figure out your environment a bit before calling the actual wkhtmltopdf binary. These can be created as part of a gem that provides wkhtmltopdf or a Ruby switcher like rbenv.

If you were to cat /usr/local/bin/wkhtmltopdf, if it looks messed up, then it's an actual binary, but I suspect yours might have a first line that looks like this:

#!/usr/bin/env ruby

and that this error seems complaining that ruby doesn't exist in the PATH for the user that is executing the app.

The solution is to find the actual binary for wkhtmltopdf and put it in your WickedPdf config like this, so that WickedPdf doesn't have to try and guess where it is:

__config/initializers/wicked_pdf.rb__

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

Or maybe something like this, if you are using a gem provided wkhtmltopdf, and the binstubs keep getting in the way:

WickedPdf.config = {
  exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/wkhtmltopdf_linux_amd64"
}

Let me know how it goes!

bibinjpalathara commented 6 years ago

When I downgrade the version of wkhtmltopdf in the server to 0.9.9 its working fine.

pastullo commented 6 years ago

Installing the following fixed this problem for me:

sudo apt-get install libxrender1

More at: https://stackoverflow.com/questions/5035601/error-running-wkhtmltopdf-error-while-loading-shared-libraries