Open panniru opened 8 years ago
If you don't provide a path to the wkhtmltopdf
binary, WickedPdf may try to run bundle exec which wkhtmltopdf
. I'm not sure why your app doesn't seem to have a Gemfile, but that might be a problem in that combination.
Try providing a full path to the executable in your config/initializers/wicked_pdf.rb
something like this:
if Rails.env.production?
WickedPdf.config = {
exe_path: Rails.root.join('bundle/ruby/2.2.0/bin/wkhtmltopdf')
}
end
(or wherever your actual binary is).
Let me know how it goes!
I already pointed the path of wkhtmltopdf in WickedPdf.config for production but it's not using the path. When I run bundle exec which wkhtmltopdf
it return a blank instead.
If you are using WickedPdf.new.render_to_string
format of invocation instead of render :pdf
, you'll need to pass the configuration as the last argument like this:
WickedPdf.new.render_to_string(template: 'pdf', other_option: true, WickedPdf.config)
# or
WickedPdf.new.render_to_string(template: 'pdf', other_option: true, { exe_path: Rails.root.join('path/to/wkhtmltopdf') })
Otherwise, please find the real actual location of the wkhtmltopdf
binary, what works when you call wkhtmltopdf --version
, as it may not be in your servers $PATH. It could be installed as a package in /usr/bin or /usr/local/bin, or it could be buried in a gem bin path as shown above.
if the wkhtmltopdf binary is installed /usr/bin/
it will just throws you up an Bad runtime
. So what I did was download the pre compiled binary and put it in /usr/local/bin
it works fine. Thanks for the response btw :)
MAC OSX:
brew install wkhtmltopdf
brew install Caskroom/cask/wkhtmltopdf
#config/initializers/wicked_pdf.rb
WickedPdf.config = {
exe_path: '/usr/local/bin/wkhtmltopdf'
}
Wicked PDf not working in my productino System. Getting error loke this.
RuntimeError (Error: Failed to execute: ["/home/ubuntu/apps/my_app/shared/bundle/ruby/2.2.0/bin/wkhtmltopdf", "-q", "--page-size", "A4", "file:////tmp/wicked_pdf20160308-14721-1lqgq4c.html", "/tmp/wicked_pdf_generated_file20160308-14721-1cez6nl.pdf"] Error: PDF could not be generated! Command Error: /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/definition.rb:22:in
build': /home/ubuntu/apps/life_circle/releases/20160301052433/Gemfile not found (Bundler::GemfileNotFound) from /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:120:in
definition' from /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler.rb:88:insetup' from /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/bundler-1.11.2/lib/bundler/setup.rb:18:in
<top (required)>' from /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire' from /home/ubuntu/.rbenv/versions/2.2.3/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in
require' ):Gem file includes
gem 'wkhtmltopdf-binary' gem 'wicked_pdf'
/config/initializers/mime_types.rb
Mime::Type.register "application/pdf", :pdf