Skip to content

Instantly share code, notes, and snippets.

@gavingmiller
Forked from wrburgess/gist:3778949
Created February 14, 2013 19:38
Show Gist options
  • Save gavingmiller/4955659 to your computer and use it in GitHub Desktop.
Save gavingmiller/4955659 to your computer and use it in GitHub Desktop.

##Refs

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
else
  exe_path = Rails.root.join('bin', 'wkhtmltopdf').to_s
  # exe_path = '/usr/local/bin/wkhtmltopdf'
end

Render PDF in Controller

  def show
    @model = Model params[:id]

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

Create a PDF View

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