-
Notifications
You must be signed in to change notification settings - Fork 5
/
README
90 lines (67 loc) · 2.18 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Ezprint
=======
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.
Installation
============
Version 1.0.0 deprecates support for Rails 2. For Rails 2.x support,
install an earlier version.
gem 'ezprint'
then run "bundle install"
Example
=======
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
Render Defaults
===============
The defaults for the render options are as follows:
layout: false
template: the template for the current controller/action
stylesheets: none
Using another PDF processor
===========================
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
Possible Gotchas
================
If you're getting a "Broken Pipe" error when rendering PDF documents, you may need to
install the wkhtmltopdf-binary gem or put it in your Gemfile.
Credits
=======
Michael Bleigh for writing the awesome princely plugin, which most of the code is reworked from.
Resources
=========
Copyright (c) 2012 Jason Stewart, released under the MIT license.