In almost any web application you create, the question of generating PDF files will pop up pretty soon.
Setup
As always, using a ruby gem in rails is pretty simple, you just add a couple of lines to the
Gemfile
gem 'wicked_pdf'
#we need the new binary here, so that we can be OS independent
gem 'wkhtmltopdf-binary', github: 'pallymore/wkhtmltopdf-binary-edge', tag: 'v0.12.2'
Usage
This setup will work pretty straightforward in the controllers, because WickedPdf registers
:pdf
request format, and you can respond to it in the same fashion as html or js in a respond_to
block. Code below is copied from the WickedPdf Readme page.