diff --git a/README.md b/README.md index 2ad52ae..b5bcab3 100644 --- a/README.md +++ b/README.md @@ -22,11 +22,15 @@ More information about [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/) coul Add this to your Gemfile: - gem 'wisepdf' +```ruby +gem 'wisepdf' +``` if you don't already have wkhtmltopdf installed on your machine you can get up and running quickly by adding this to your Gemfile: - gem 'wkhtmltopdf-binary' +```ruby +gem 'wkhtmltopdf-binary' +``` then do: @@ -36,89 +40,93 @@ then do: ### Basic Usage - class ThingsController < ApplicationController - def show - respond_to do |format| - format.html - format.pdf do - render :pdf => "file_name" - end - end +```ruby +class ThingsController < ApplicationController + def show + respond_to do |format| + format.html + format.pdf do + render :pdf => "file_name" end end + end +end +``` ### Advanced Usage with all available options - class ThingsController < ApplicationController - def show - respond_to do |format| - format.html - format.pdf do - render :pdf => 'file_name', - :template => 'things/show.pdf.erb', - :layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file - :show_as_html => params[:debug].present?, # allow debuging based on url param - :orientation => 'Landscape', # default Portrait - :page_size => 'A4, Letter, ...', # default A4 - :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"), - :save_only => false, # depends on :save_to_file being set first - :proxy => 'TEXT', - :basic_auth => false # when true username & password are automatically sent from session - :username => 'TEXT', - :password => 'TEXT', - :cover => 'URL', - :dpi => 'dpi', - :encoding => 'TEXT', - :user_style_sheet => 'URL', - :cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format - :post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format - :redirect_delay => NUMBER, - :zoom => FLOAT, - :page_offset => NUMBER, - :book => true, - :default_header => true, - :disable_javascript => false, - :greyscale => true, - :lowquality => true, - :enable_plugins => true, - :disable_internal_links => true, - :disable_external_links => true, - :print_media_type => true, - :disable_smart_shrinking => true, - :use_xserver => true, - :no_background => true, - :margin => {:top => SIZE, # default 10 (mm) - :bottom => SIZE, - :left => SIZE, - :right => SIZE}, - :header => {:html => { :template => 'users/header.pdf.erb', # use :template OR :url - :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout - :url => 'www.example.com', - :locals => { :foo => @bar }}, - :center => 'TEXT', - :font_name => 'NAME', - :font_size => SIZE, - :left => 'TEXT', - :right => 'TEXT', - :spacing => REAL, - :line => true}, - :footer => {:html => { :template => 'shared/footer.pdf.erb', # use :template OR :url - :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout - :url => 'www.example.com', - :locals => { :foo => @bar }}, - :center => 'TEXT', - :font_name => 'NAME', - :font_size => SIZE, - :left => 'TEXT', - :right => 'TEXT', - :spacing => REAL, - :line => true}, - :outline => {:outline => true, - :outline_depth => LEVEL} - end - end +```ruby +class ThingsController < ApplicationController + def show + respond_to do |format| + format.html + format.pdf do + render :pdf => 'file_name', + :template => 'things/show.pdf.erb', + :layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file + :show_as_html => params[:debug].present?, # allow debuging based on url param + :orientation => 'Landscape', # default Portrait + :page_size => 'A4, Letter, ...', # default A4 + :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"), + :save_only => false, # depends on :save_to_file being set first + :proxy => 'TEXT', + :basic_auth => false # when true username & password are automatically sent from session + :username => 'TEXT', + :password => 'TEXT', + :cover => 'URL', + :dpi => 'dpi', + :encoding => 'TEXT', + :user_style_sheet => 'URL', + :cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format + :post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format + :redirect_delay => NUMBER, + :zoom => FLOAT, + :page_offset => NUMBER, + :book => true, + :default_header => true, + :disable_javascript => false, + :greyscale => true, + :lowquality => true, + :enable_plugins => true, + :disable_internal_links => true, + :disable_external_links => true, + :print_media_type => true, + :disable_smart_shrinking => true, + :use_xserver => true, + :no_background => true, + :margin => {:top => SIZE, # default 10 (mm) + :bottom => SIZE, + :left => SIZE, + :right => SIZE}, + :header => {:html => { :template => 'users/header.pdf.erb', # use :template OR :url + :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout + :url => 'www.example.com', + :locals => { :foo => @bar }}, + :center => 'TEXT', + :font_name => 'NAME', + :font_size => SIZE, + :left => 'TEXT', + :right => 'TEXT', + :spacing => REAL, + :line => true}, + :footer => {:html => { :template => 'shared/footer.pdf.erb', # use :template OR :url + :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout + :url => 'www.example.com', + :locals => { :foo => @bar }}, + :center => 'TEXT', + :font_name => 'NAME', + :font_size => SIZE, + :left => 'TEXT', + :right => 'TEXT', + :spacing => REAL, + :line => true}, + :outline => {:outline => true, + :outline_depth => LEVEL} end end + end +end +``` By default, it will render without a layout (:layout => false) and the template for the current controller and action. @@ -126,94 +134,106 @@ By default, it will render without a layout (:layout => false) and the template If you need to just create a pdf and not display it: - # create a pdf from a string - pdf = Wisepdf::Writer.new.to_pdf('