jcrisp / wicked_pdf forked from galdomedia/wicked_pdf

PDF generator (from HTML) plugin for Ruby on Rails

This URL has Read+Write access

name age message
file .gitignore Wed Nov 11 16:39:38 -0800 2009 add gitignore [James Crisp]
file MIT-LICENSE Tue Jun 16 13:57:57 -0700 2009 Initial commit [mileszs]
file README.md Wed Nov 11 20:09:31 -0800 2009 Updating README [James Crisp]
file Rakefile Wed Nov 11 16:32:36 -0800 2009 Adding empty spec test [James Crisp]
file init.rb Tue Jun 16 13:57:57 -0700 2009 Initial commit [mileszs]
directory lib/ Wed Nov 11 19:50:59 -0800 2009 More error handling [James Crisp]
directory spec/ Wed Nov 11 19:50:59 -0800 2009 More error handling [James Crisp]
README.md

Wicked PDF

A PDF generation plugin for Ruby on Rails

Wicked PDF uses the shell utility wkhtmltopdf to serve a PDF file to a user from HTML. In other words, rather than dealing with a PDF generation DSL of some sort, you simply write an HTML view as you would normally, and let Wicked take care of the hard stuff.

Installation

First, be sure to install wkhtmltopdf. Note that versions before 0.9.0 have problems on some machines with reading/writing to streams. This plugin relies on streams to communicate with wkhtmltopdf.

Next:

script/plugin install git://github.com/jcrisp/wicked_pdf.git

Usage

class ThingsController < ApplicationController
  def show
    respond_to do |format|
      format.html
      format.pdf do
        render :pdf => "file_name", 
               :template => "things/show.pdf.erb", # OPTIONAL
               :layout => "pdf.html", # OPTIONAL
               :wkhtmltopdf => '/usr/local/bin/wkhtmltopdf' # OPTIONAL, path to binary
      end
    end
  end
end

By default, it will render without a layout (:layout => false) and the template for the current controller and action. (So, the template line in the above code is actually unnecessary.)

Inspiration

You may have noticed: this plugin is heavily inspired by the PrinceXML plugin princely. PrinceXML's cost was prohibitive for me. So, with a little help from some friends (thanks jqr), I tracked down wkhtmltopdf, and here we are.