Path: | README.rdoc |
Last Update: | Thu Apr 25 04:08:05 +0000 2013 |
Ezprint is a drop in replacement for the princely plugin. It uses PDFKit as the backend instead of princexml, possibly saving you millions of dollars. I recommend using the Rack middleware component of PDFKit to print PDFs in rails, but this plugin makes an easy transition from prince->PDFKit for those using princely.
gem install ezprint
in environment.rb config.gem "ezprint"
gem ‘ezprint‘
then run "bundle install"
The examples here are similar to princely, since the plugin is basically a reworking of the princely source class PDFExample < ApplicationController def show respond_to do |format| format.html format.pdf do render :pdf => "My Awesome PDF", :template => "controller/action.pdf.erb", :stylesheets => ["application","print"] :layout => "pdf" end end end # Alternatively, you can use make_and_send_pdf to # render out a PDF for the action without a # respond_to block. def pdf make_and_send_pdf("file_name") end end
The defaults for the render options are as follows:
layout: false template: the template for the current controller/action stylesheets: none
While ezprint has been designed with PDFKit in mind, other PDF processors such as princexml can be used. A princexml processor is included and can be used by setting Ezprint.processor = :prince in an initializer.
It‘s also easy to create your own processor:
module Ezprint module Processors class MyProcessor < Base def self.process(html_string, options = {}) # Code to return a PDF string from an html string here. end end end end