Rails-wicked_pdf gem export data on heroku

2018, Dec 02    

If we want to export our records as pdf in rails, we can use wicked_pdf or another gems. I used wicked_pdf. Because easy to configuration and set up. wicked_pdf gem is using wkhtmltopdf to serve a PDF file to a user from HTML. When you set up configuration this page everything is okay. Your records will be successfully exported as pdf. But if you want to deploy your app heroku or another system, you should make a few configuration. I will tell heroku configuration this post.

Firs Step — Download wkhtmltopdf

You need to wkhtmltopdf-amd64 project. Download this project and create a folder in your root directory. Call the folder as bin. And copy wkhtmltopdf-amd64 project inside bin folder.

Second Step — Set up the Configuration


if Rails.env.staging? || Rails.env.production?
  exe_path = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
  WickedPdf.config = {
     exe_path:  'C:\wkhtmltopdf\bin\wkhtmltopdf.exe'

Last Step

In production mode, you need to do the following configurations in order not to have any problems in your asset files.


config.serve_static_assets = true


Rails.application.config.assets.precompile += %w( nested_form.js application.css.scss application.js )


set up wicked gem