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.
This sollution (with TmpFile) may (will?) not work, if you're using ruby 1.8.6. Use 1.8.7 instead.
First, be sure to install wkhtmltopdf.
Next:
script/plugin install git://github.com/mileszs/wicked_pdf.git
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.)
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.