Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wicked_pdf on production server

Locally It works like magic but when I try to generate the PDF on the server it trows:

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

Here's what's 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'
like image 558
Mr_Nizzle Avatar asked Dec 03 '22 04:12

Mr_Nizzle


1 Answers

Fixed removing system installed wkhtmltopdf and using the binary of wkhtmltopdf:

  1. Uninstall the wkhtmltopdf package: apt-get remove wkhtmltopdf --purge
  2. (in usr/local/bin) sudo curl -C - -O http://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.9.9-static-amd64.tar.bz2
  3. (in usr/local/bin) sudo tar -xvjf wkhtmltopdf-0.9.9-static-amd64.tar.bz2
  4. (in usr/local/bin) ln -s wkhtmltopdf-amd64 wkhtmltopdf
  5. In your initializer WickedPdf.config = { :exe_path => "/usr/local/bin/wkhtmltopdf" }
like image 74
Mr_Nizzle Avatar answered Dec 23 '22 22:12

Mr_Nizzle