wicked_pdf on production server
-
12-12-2019 - |
Question
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'
Solution
Fixed removing system installed wkhtmltopdf
and using the binary of wkhtmltopdf:
- Uninstall 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" }
OTHER TIPS
For others experiencing this issue, we had the same error message with a different solution. We didn't have a headless browser running:
sudo apt-get install xvfb
solved it
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow