README.md in wicked_pdf-0.9.0 vs README.md in wicked_pdf-0.9.1
- old
+ new
@@ -52,10 +52,11 @@
format.html
format.pdf do
render :pdf => 'file_name',
:disposition => 'attachment', # default 'inline'
:template => 'things/show.pdf.erb',
+ :file => "#{Rails.root}/files/foo.erb"
:layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file
:wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
:show_as_html => params[:debug].present?, # allow debuging based on url param
:orientation => 'Landscape', # default Portrait
:page_size => 'A4, Letter, ...', # default A4
@@ -154,11 +155,11 @@
# create a pdf from string using templates, layouts and content option for header or footer
WickedPdf.new.pdf_from_string(
render_to_string(:pdf => "pdf_file.pdf", :template => 'templates/pdf.html.erb', :layout => 'pdfs/layout_pdf'),
:footer => {:content => render_to_string({:template => 'templates/pdf_footer.html.erb', :layout => 'pdfs/layout_pdf'})}
-
+ )
# or from your controller, using views & templates and all wicked_pdf options as normal
pdf = render_to_string :pdf => "some_file_name"
# then save to a file
save_path = Rails.root.join('pdfs','filename.pdf')
@@ -223,9 +224,25 @@
render :pdf => 'filename', :header => { :right => '[page] of [topage]' }
### Configuration
You can put your default configuration, applied to all pdf's at "wicked_pdf.rb" initializer.
+
+### Rack Middleware
+
+If you would like to have WickedPdf automatically generate PDF views for all (or nearly all) pages by appending .pdf to the URL, add the following to your Rails app:
+
+ # in application.rb (Rails3) or environment.rb (Rails2)
+ require 'wicked_pdf'
+ config.middleware.use WickedPdf::Middleware
+
+If you want to turn on or off the middleware for certain urls, use the `:only` or `:except` conditions like so:
+
+ # conditions can be plain strings or regular expressions, and you can supply only one or an array
+ config.middleware.use WickedPdf::Middleware, {}, :only => '/invoice'
+ config.middleware.use WickedPdf::Middleware, {}, :except => [ %r[^/admin], '/secret', %r[^/people/\d] ]
+
+If you use the standard `render :pdf => 'some_pdf'` in your app, you will want to exclude those actions from the middleware.
### Further Reading
Andreas Happe's post [Generating PDFs from Ruby on Rails](http://www.snikt.net/blog/2012/04/26/wicked-pdf/)