Can be used to generate PDFs and supports HTML to PDF.
- Add
gem 'wicked_pdf'
to the main section ofGemfile
- Add
gem 'wkhtmltopdf-binary'
togroup :development, :test
- Add
gem 'wkhtmltopdf-heroku'
togroup :production
By default, it adds no layout, you you may want to add a layout:
- Create a
pdf.pdf.erb
- Use the method to add stylesheets :
wicked_pdf_stylesheet_link_tag 'pdf', media: 'all'
- Use the method
wicked_pdf_image_tag
to insert images to the layout.
Usage:
render pdf: <<filename>>, print_media_type: true, layout: 'pdf', disposition: 'attachment'
Ensure that fonts are installed on Heroku, otherwise the PDF will look different compared to the one generated locally. The fonts need to be installed with a buildpack and put in the ~/.fonts
folder.
If you need Arial, you can add the following buildpack on Heroku:
https://github.com/propertybase/heroku-buildpack-fonts
heroku/ruby
!