Instantly share code, notes, and snippets.

What would you like to do?
Setup wicked_pdf and wkhtmltopdf with Rails 3 and Heroku


Install wicked_pdf

Add to Gemfile: gem 'wicked_pdf'

In terminal: bundle

For local, install wkhtmltopdf

In terminal: git checkout 6e2d550 /usr/local/Library/Formula/wkhtmltopdf.rb

In terminal: brew install wkhtmltopdf

Make sure you installed wkhtmltopdf 0.9.9

For Heroku, download wkhtmltopdf

Go to wkhtmltopdf

Download the wkhtmltopdf-0.9.9 Linux Static Binary (amd64) binary

Copy the binary to ``bin/wkhtmltopdf-amd64```

Install QT

In terminal: brew install qt

Set up the Config

Create a file: config/wicked_pdf.rb

if Rails.env.staging? || Rails.env.production?
  exe_path = Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s
  exe_path = Rails.root.join('bin', 'wkhtmltopdf').to_s
  # exe_path = '/usr/local/bin/wkhtmltopdf'

Render PDF in Controller

  def show
    @model = Model params[:id]

    respond_to do |format|
      format.csv do
        model_csv =
        send_data(model_csv.to_csv, filename: model_csv.generate_csv_filename)
      format.pdf do
        render pdf: "#{@model.uuid}",
               template: 'admin/modelss/show.pdf.haml',
               disposition: 'attachment',
               :toc => { :depth => 2, :header_text => 'TEXT', disable_links: false }

Create a PDF View


This comment has been minimized.

Copy link

obromios commented Apr 19, 2013

Thank you this was very useful. One minor clarification is that my local wkhtmltopdf binary was stored in a different place, so my config/initializers/wicked_pdf.rb file was a bit different. As well, the full config syntax is shown below.

if Rails.env.staging? || Rails.env.production?
  WickedPdf.config = {:exe_path => Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s}
  WickedPdf.config = { :exe_path => '/usr/bin/wkhtmltopdf'}

This comment has been minimized.

Copy link

kathgironpe commented Oct 8, 2014

If you use Rails Config gem. It is much cleaner.

   wkhtmltopdf_path: "<%= Rails.root.join('bin', 'wkhtmltopdf-amd64').to_s %>"

This comment has been minimized.

Copy link

jancel commented May 2, 2015

This is well outdated. Where can we get the current linux static binary? I'm looking around, looks like I need to extract it.


This comment has been minimized.

Copy link

eltiare commented May 8, 2015

@jancel You can get the static binaries here:


This comment has been minimized.

Copy link

iyanski commented Jun 15, 2015


This comment has been minimized.

Copy link

wintondeshong commented Jun 24, 2015

Running wkhtmltopdf on OS X 10.10.3 in a Ruby 2.2.2 Rails 4.2.2 project for local development via...

brew install caskroom/cask/brew-cask
brew cask install wkhtmltopdf

Then used the amd64 binary from out of app's bin directory (as described above) on Heroku for staging and production environments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment