Wicked_pdf on the production server

Locally This works like magic, but when I try to create a PDF on the server, it throws:

RuntimeError (Failed to execute: "/path/to/my/project/vendor/bundle/ruby/1.9.1/bin/wkhtmltopdf" -q - - Error: Broken pipe): 

Here that on my_controller .

 format.pdf do pdf = render_to_string( :pdf => "invoice", :template => "my_controller/my_view.pdf.erb", :layout=>"pdf.html.erb" ) save_path = Rails.root.join('pdfs','invoice.pdf') File.open(save_path, 'wb') do |file| file << pdf end send_file(save_path) end 

And in my gemfile

 gem 'wicked_pdf' gem 'wkhtmltopdf-binary' 
+4
source share
2 answers

Installed wkhtmltopdf removal wkhtmltopdf and using the wkhtmltopdf binary file:

  • Remove the wkhtmltopdf package: apt-get remove wkhtmltopdf --purge
  • (in usr / local / bin) sudo curl -C - -O http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
  • (in usr / local / bin) sudo tar -xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
  • (in usr / local / bin) ln -s wkhtmltopdf-amd64 wkhtmltopdf
  • In your initializer, WickedPdf.config = { :exe_path => "/usr/local/bin/wkhtmltopdf" }
+17
source

For others who encountered this problem, we had the same error message with a different solution. We did not have a browser without a browser:

 sudo apt-get install xvfb 

I decided

0
source

Source: https://habr.com/ru/post/1401036/


All Articles