wicked_pdf 0.11.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -1
- data/.travis.yml +13 -3
- data/Gemfile +1 -1
- data/README.md +152 -142
- data/Rakefile +24 -12
- data/gemfiles/2.3.gemfile +2 -0
- data/gemfiles/3.1.gemfile +3 -2
- data/gemfiles/3.2.gemfile +3 -2
- data/gemfiles/4.0.gemfile +2 -2
- data/gemfiles/4.1.gemfile +6 -0
- data/gemfiles/4.2.gemfile +6 -0
- data/gemfiles/rails_edge.gemfile +3 -3
- data/generators/wicked_pdf/templates/wicked_pdf.rb +19 -3
- data/generators/wicked_pdf/wicked_pdf_generator.rb +1 -1
- data/lib/generators/wicked_pdf_generator.rb +2 -2
- data/lib/wicked_pdf.rb +241 -212
- data/lib/wicked_pdf/middleware.rb +6 -7
- data/lib/wicked_pdf/pdf_helper.rb +53 -53
- data/lib/wicked_pdf/railtie.rb +14 -14
- data/lib/wicked_pdf/tempfile.rb +2 -2
- data/lib/wicked_pdf/version.rb +2 -2
- data/lib/wicked_pdf/wicked_pdf_helper.rb +30 -15
- data/test/functional/pdf_helper_test.rb +5 -5
- data/test/functional/wicked_pdf_helper_assets_test.rb +35 -8
- data/test/functional/wicked_pdf_helper_test.rb +2 -2
- data/test/test_helper.rb +10 -5
- data/test/unit/wicked_pdf_test.rb +90 -57
- data/wicked_pdf.gemspec +5 -4
- metadata +20 -72
- data/test/dummy/README.rdoc +0 -261
- data/test/dummy/Rakefile +0 -7
- data/test/dummy/app/assets/javascripts/application.js +0 -15
- data/test/dummy/app/assets/stylesheets/application.css +0 -13
- data/test/dummy/app/controllers/application_controller.rb +0 -3
- data/test/dummy/app/helpers/application_helper.rb +0 -2
- data/test/dummy/app/mailers/.gitkeep +0 -0
- data/test/dummy/app/models/.gitkeep +0 -0
- data/test/dummy/app/views/layouts/application.html.erb +0 -14
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -59
- data/test/dummy/config/boot.rb +0 -10
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -37
- data/test/dummy/config/environments/production.rb +0 -67
- data/test/dummy/config/environments/test.rb +0 -37
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/inflections.rb +0 -15
- data/test/dummy/config/initializers/mime_types.rb +0 -5
- data/test/dummy/config/initializers/secret_token.rb +0 -7
- data/test/dummy/config/initializers/session_store.rb +0 -8
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -5
- data/test/dummy/config/routes.rb +0 -58
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/assets/.gitkeep +0 -0
- data/test/dummy/log/.gitkeep +0 -0
- data/test/dummy/public/404.html +0 -26
- data/test/dummy/public/422.html +0 -26
- data/test/dummy/public/500.html +0 -25
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dd7dae1230ac2e120e6ca1cb235a8f21465df966
|
4
|
+
data.tar.gz: c66399843e25433bc83ac7970ff392f2a217bf95
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86a57ed7f58c19916f48c8cfc98074c5e6cb3ca060c1563abbb2c62e2c0eecefeaba635502ece68c870be7b4049422ef7fd326d59507a6a8709d3938def96491
|
7
|
+
data.tar.gz: e97feccdf135d2e74d2d14e9ba1e944c130ed631c27a2f18c46e5be1f6804ac439e75755a0a3ddeffffe877d33547c07c76f13980b5b42d0eda45f243f98e399
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
language:
|
2
2
|
- ruby
|
3
3
|
bundler_args: --verbose
|
4
|
-
rvm:
|
4
|
+
rvm:
|
5
5
|
- 1.9.2
|
6
6
|
- 1.9.3
|
7
|
-
- 2.0
|
7
|
+
- 2.0
|
8
|
+
- 2.1
|
9
|
+
- 2.2
|
8
10
|
gemfile:
|
9
11
|
- gemfiles/3.0.gemfile
|
10
12
|
- gemfiles/3.1.gemfile
|
11
13
|
- gemfiles/3.2.gemfile
|
12
|
-
before_script:
|
14
|
+
before_script:
|
13
15
|
- bundle list
|
14
16
|
- sudo apt-get install -y wkhtmltopdf
|
15
17
|
- "export DISPLAY=:99.0"
|
@@ -33,8 +35,16 @@ matrix:
|
|
33
35
|
gemfile: gemfiles/4.0.gemfile
|
34
36
|
- rvm: 2.0.0
|
35
37
|
gemfile: gemfiles/rails_edge.gemfile
|
38
|
+
- rvm: 2.2.0
|
39
|
+
gemfile: gemfiles/4.1.gemfile
|
40
|
+
- rvm: 2.2.0
|
41
|
+
gemfile: gemfiles/4.2.gemfile
|
42
|
+
- rvm: 2.2.0
|
43
|
+
gemfile: gemfiles/rails_edge.gemfile
|
36
44
|
allow_failures:
|
37
45
|
- rvm: 1.9.3
|
38
46
|
gemfile: gemfiles/rails_edge.gemfile
|
39
47
|
- rvm: 2.0.0
|
40
48
|
gemfile: gemfiles/rails_edge.gemfile
|
49
|
+
- rvm: 2.2.0
|
50
|
+
gemfile: gemfiles/rails_edge.gemfile
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,54 +1,49 @@
|
|
1
|
-
# Wicked PDF [![Build Status](https://secure.travis-ci.org/mileszs/wicked_pdf.png)](http://travis-ci.org/mileszs/wicked_pdf)
|
1
|
+
# Wicked PDF [![Build Status](https://secure.travis-ci.org/mileszs/wicked_pdf.png)](http://travis-ci.org/mileszs/wicked_pdf) [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf)
|
2
2
|
|
3
3
|
## A PDF generation plugin for Ruby on Rails
|
4
4
|
|
5
|
-
Wicked PDF uses the shell utility [wkhtmltopdf](http://
|
5
|
+
Wicked PDF uses the shell utility [wkhtmltopdf](http://wkhtmltopdf.org) 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, then let Wicked PDF take care of the hard stuff.
|
6
6
|
|
7
|
-
_Wicked PDF has been verified to work on Ruby 1.8.7
|
7
|
+
_Wicked PDF has been verified to work on Ruby versions 1.8.7 through 2.1; Rails 2 through 4.1_
|
8
8
|
|
9
9
|
### Installation
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
One simple way to install all of the binaries (Linux, OSX, Windows) is through the gem [wkhtmltopdf-binary](https://github.com/steerio/wkhtmltopdf-binary).
|
14
|
-
To install, simply add
|
11
|
+
Add this to your Gemfile and run `bundle install`:
|
15
12
|
|
16
13
|
```ruby
|
17
|
-
gem '
|
14
|
+
gem 'wicked_pdf'
|
18
15
|
```
|
19
16
|
|
20
|
-
|
17
|
+
Then create the initializer with
|
21
18
|
|
22
|
-
|
19
|
+
rails generate wicked_pdf
|
23
20
|
|
21
|
+
You may also need to add
|
24
22
|
```ruby
|
25
|
-
|
26
|
-
:exe_path => '/usr/local/bin/wkhtmltopdf'
|
27
|
-
}
|
23
|
+
Mime::Type.register "application/pdf", :pdf
|
28
24
|
```
|
29
|
-
|
30
|
-
This plugin relies on streams to communicate with wkhtmltopdf.
|
31
|
-
|
32
|
-
For more information about wkhtmltopdf, see the project's [homepage](http://code.google.com/p/wkhtmltopdf/) and
|
33
|
-
[github repo](https://github.com/antialize/wkhtmltopdf). There's also some documentation for a recent, stable version
|
34
|
-
on the author's website, [here](http://madalgo.au.dk/~jakobt/wkhtmltoxdoc/wkhtmltopdf-0.9.9-doc.html).
|
35
|
-
|
36
|
-
Next:
|
25
|
+
to `config/initializers/mime_types.rb` in older versions of Rails.
|
37
26
|
|
38
|
-
|
39
|
-
script/generate wicked_pdf
|
27
|
+
Because `wicked_pdf` is a wrapper for [wkhtmltopdf](http://wkhtmltopdf.org/), you'll need to install that, too.
|
40
28
|
|
41
|
-
|
29
|
+
The simplest way to install all of the binaries (Linux, OSX, Windows) is through the gem [wkhtmltopdf-binary](https://github.com/steerio/wkhtmltopdf-binary).
|
30
|
+
To install that, add a second gem
|
42
31
|
|
43
32
|
```ruby
|
44
|
-
gem '
|
33
|
+
gem 'wkhtmltopdf-binary'
|
45
34
|
```
|
46
35
|
|
47
|
-
|
36
|
+
To your Gemfile and run `bundle install`.
|
37
|
+
|
38
|
+
If your wkhtmltopdf executable is not on your webserver's path, you can configure it in an initializer:
|
39
|
+
|
48
40
|
```ruby
|
49
|
-
|
41
|
+
WickedPdf.config = {
|
42
|
+
exe_path: '/usr/local/bin/wkhtmltopdf'
|
43
|
+
}
|
50
44
|
```
|
51
|
-
|
45
|
+
|
46
|
+
For more information about `wkhtmltopdf`, see the project's [homepage](http://wkhtmltopdf.org/).
|
52
47
|
|
53
48
|
### Basic Usage
|
54
49
|
```ruby
|
@@ -57,7 +52,7 @@ class ThingsController < ApplicationController
|
|
57
52
|
respond_to do |format|
|
58
53
|
format.html
|
59
54
|
format.pdf do
|
60
|
-
render :
|
55
|
+
render pdf: "file_name" # Excluding ".pdf" extension.
|
61
56
|
end
|
62
57
|
end
|
63
58
|
end
|
@@ -69,11 +64,10 @@ The wkhtmltopdf binary is run outside of your Rails application; therefore, your
|
|
69
64
|
|
70
65
|
#### wicked_pdf helpers
|
71
66
|
```html
|
72
|
-
<!
|
73
|
-
|
74
|
-
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
67
|
+
<!doctype html>
|
68
|
+
<html>
|
75
69
|
<head>
|
76
|
-
<meta
|
70
|
+
<meta charset='utf-8' />
|
77
71
|
<%= wicked_pdf_stylesheet_link_tag "pdf" -%>
|
78
72
|
<%= wicked_pdf_javascript_include_tag "number_pages" %>
|
79
73
|
</head>
|
@@ -91,8 +85,8 @@ The wkhtmltopdf binary is run outside of your Rails application; therefore, your
|
|
91
85
|
|
92
86
|
In this case, you can use that standard Rails helpers and point to the current CDN for whichever framework you are using. For jQuery, it would look somethng like this, given the current versions at the time of this writing.
|
93
87
|
```html
|
94
|
-
<!
|
95
|
-
<html
|
88
|
+
<!doctype html>
|
89
|
+
<html>
|
96
90
|
<head>
|
97
91
|
<%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
|
98
92
|
<%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
|
@@ -110,104 +104,112 @@ class ThingsController < ApplicationController
|
|
110
104
|
respond_to do |format|
|
111
105
|
format.html
|
112
106
|
format.pdf do
|
113
|
-
render :
|
114
|
-
:
|
115
|
-
:
|
116
|
-
:
|
117
|
-
:
|
118
|
-
:
|
119
|
-
:
|
120
|
-
:
|
121
|
-
:
|
122
|
-
:
|
123
|
-
:
|
124
|
-
:
|
125
|
-
:
|
126
|
-
:
|
127
|
-
:password
|
128
|
-
:
|
129
|
-
:
|
130
|
-
:
|
131
|
-
:
|
132
|
-
:
|
133
|
-
:
|
134
|
-
:
|
135
|
-
:
|
136
|
-
:
|
137
|
-
:
|
138
|
-
:
|
139
|
-
:
|
140
|
-
:
|
141
|
-
:
|
142
|
-
:
|
143
|
-
:
|
144
|
-
:
|
145
|
-
:
|
146
|
-
:
|
147
|
-
:
|
148
|
-
:
|
149
|
-
:
|
150
|
-
:
|
151
|
-
:
|
152
|
-
:
|
153
|
-
:
|
154
|
-
:
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
:
|
107
|
+
render pdf: 'file_name',
|
108
|
+
disposition: 'attachment', # default 'inline'
|
109
|
+
template: 'things/show.pdf.erb',
|
110
|
+
file: "#{Rails.root}/files/foo.erb"
|
111
|
+
layout: 'pdf.html', # use 'pdf.html' for a pdf.html.erb file
|
112
|
+
wkhtmltopdf: '/usr/local/bin/wkhtmltopdf', # path to binary
|
113
|
+
show_as_html: params.key?('debug'), # allow debugging based on url param
|
114
|
+
orientation: 'Landscape', # default Portrait
|
115
|
+
page_size: 'A4, Letter, ...', # default A4
|
116
|
+
page_height: NUMBER,
|
117
|
+
page_width: NUMBER,
|
118
|
+
save_to_file: Rails.root.join('pdfs', "#{filename}.pdf"),
|
119
|
+
save_only: false, # depends on :save_to_file being set first
|
120
|
+
proxy: 'TEXT',
|
121
|
+
basic_auth: false # when true username & password are automatically sent from session
|
122
|
+
username: 'TEXT',
|
123
|
+
password: 'TEXT',
|
124
|
+
title: 'Alternate Title', # otherwise first page title is used
|
125
|
+
cover: 'URL, Pathname, or raw HTML string',
|
126
|
+
dpi: 'dpi',
|
127
|
+
encoding: 'TEXT',
|
128
|
+
user_style_sheet: 'URL',
|
129
|
+
cookie: ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
|
130
|
+
post: ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
|
131
|
+
redirect_delay: NUMBER,
|
132
|
+
javascript_delay: NUMBER,
|
133
|
+
image_quality: NUMBER,
|
134
|
+
no_pdf_compression: true,
|
135
|
+
zoom: FLOAT,
|
136
|
+
page_offset: NUMBER,
|
137
|
+
book: true,
|
138
|
+
default_header: true,
|
139
|
+
disable_javascript: false,
|
140
|
+
grayscale: true,
|
141
|
+
lowquality: true,
|
142
|
+
enable_plugins: true,
|
143
|
+
disable_internal_links: true,
|
144
|
+
disable_external_links: true,
|
145
|
+
print_media_type: true,
|
146
|
+
disable_smart_shrinking: true,
|
147
|
+
use_xserver: true,
|
148
|
+
no_background: true,
|
149
|
+
viewport_size: 'TEXT', # available only with use_xserver or patched QT
|
150
|
+
extra: '', # directly inserted into the command to wkhtmltopdf
|
151
|
+
outline: { outline: true,
|
152
|
+
outline_depth: LEVEL },
|
153
|
+
margin: { top: SIZE, # default 10 (mm)
|
154
|
+
bottom: SIZE,
|
155
|
+
left: SIZE,
|
156
|
+
right: SIZE },
|
157
|
+
header: { html: { template: 'users/header.pdf.erb', # use :template OR :url
|
158
|
+
layout: 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
|
159
|
+
url: 'www.example.com',
|
160
|
+
locals: { foo: @bar }},
|
161
|
+
center: 'TEXT',
|
162
|
+
font_name: 'NAME',
|
163
|
+
font_size: SIZE,
|
164
|
+
left: 'TEXT',
|
165
|
+
right: 'TEXT',
|
166
|
+
spacing: REAL,
|
167
|
+
line: true,
|
168
|
+
content: 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
|
169
|
+
footer: { html: { template:'shared/footer.pdf.erb', # use :template OR :url
|
170
|
+
layout: 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
|
171
|
+
url: 'www.example.com',
|
172
|
+
locals: { foo: @bar }},
|
173
|
+
center: 'TEXT',
|
174
|
+
font_name: 'NAME',
|
175
|
+
font_size: SIZE,
|
176
|
+
left: 'TEXT',
|
177
|
+
right: 'TEXT',
|
178
|
+
spacing: REAL,
|
179
|
+
line: true,
|
180
|
+
content: 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
|
181
|
+
toc: { font_name: "NAME",
|
182
|
+
depth: LEVEL,
|
183
|
+
header_text: "TEXT",
|
184
|
+
header_fs: SIZE,
|
185
|
+
text_size_shrink: 0.8,
|
186
|
+
l1_font_size: SIZE,
|
187
|
+
l2_font_size: SIZE,
|
188
|
+
l3_font_size: SIZE,
|
189
|
+
l4_font_size: SIZE,
|
190
|
+
l5_font_size: SIZE,
|
191
|
+
l6_font_size: SIZE,
|
192
|
+
l7_font_size: SIZE,
|
193
|
+
level_indentation: NUM,
|
194
|
+
l1_indentation: NUM,
|
195
|
+
l2_indentation: NUM,
|
196
|
+
l3_indentation: NUM,
|
197
|
+
l4_indentation: NUM,
|
198
|
+
l5_indentation: NUM,
|
199
|
+
l6_indentation: NUM,
|
200
|
+
l7_indentation: NUM,
|
201
|
+
no_dots: true,
|
202
|
+
disable_dotted_lines: true,
|
203
|
+
disable_links: true,
|
204
|
+
disable_toc_links: true,
|
205
|
+
disable_back_links:true,
|
206
|
+
xsl_style_sheet: 'file.xsl'} # optional XSLT stylesheet to use for styling table of contents
|
205
207
|
end
|
206
208
|
end
|
207
209
|
end
|
208
210
|
end
|
209
211
|
```
|
210
|
-
By default, it will render without a layout (:
|
212
|
+
By default, it will render without a layout (layout: false) and the template for the current controller and action.
|
211
213
|
|
212
214
|
### Super Advanced Usage ###
|
213
215
|
|
@@ -220,16 +222,19 @@ pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
|
|
220
222
|
# Path must be absolute path
|
221
223
|
pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
|
222
224
|
|
225
|
+
# create a pdf from a URL
|
226
|
+
pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf')
|
227
|
+
|
223
228
|
# create a pdf from string using templates, layouts and content option for header or footer
|
224
|
-
WickedPdf.new.pdf_from_string(
|
225
|
-
render_to_string('templates/pdf.html.erb', :
|
226
|
-
:
|
227
|
-
:
|
229
|
+
pdf = WickedPdf.new.pdf_from_string(
|
230
|
+
render_to_string('templates/pdf.html.erb', layout: 'pdfs/layout_pdf'),
|
231
|
+
footer: {
|
232
|
+
content: render_to_string(layout: 'pdfs/layout_pdf')
|
228
233
|
}
|
229
234
|
)
|
230
235
|
|
231
236
|
# or from your controller, using views & templates and all wicked_pdf options as normal
|
232
|
-
pdf = render_to_string :pdf
|
237
|
+
pdf = render_to_string pdf: "some_file_name", template: "templates/pdf.html.erb", encoding: "UTF-8"
|
233
238
|
|
234
239
|
# then save to a file
|
235
240
|
save_path = Rails.root.join('pdfs','filename.pdf')
|
@@ -239,7 +244,7 @@ end
|
|
239
244
|
```
|
240
245
|
If you need to display utf encoded characters, add this to your pdf views or layouts:
|
241
246
|
```html
|
242
|
-
<meta
|
247
|
+
<meta charset="utf-8" />
|
243
248
|
```
|
244
249
|
### Page Numbering
|
245
250
|
|
@@ -251,7 +256,7 @@ A bit of javascript can help you number your pages. Create a template or header/
|
|
251
256
|
function number_pages() {
|
252
257
|
var vars={};
|
253
258
|
var x=document.location.search.substring(1).split('&');
|
254
|
-
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] =
|
259
|
+
for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = decodeURIComponent(z[1]);}
|
255
260
|
var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
|
256
261
|
for(var i in x) {
|
257
262
|
var y = document.getElementsByClassName(x[i]);
|
@@ -269,7 +274,7 @@ Anything with a class listed in "var x" above will be auto-filled at render time
|
|
269
274
|
|
270
275
|
If you do not have explicit page breaks (and therefore do not have any "page" class), you can also use wkhtmltopdf's built in page number generation by setting one of the headers to "[page]":
|
271
276
|
```ruby
|
272
|
-
render :
|
277
|
+
render pdf: 'filename', header: { right: '[page] of [topage]' }
|
273
278
|
```
|
274
279
|
### Configuration
|
275
280
|
|
@@ -286,10 +291,10 @@ config.middleware.use WickedPdf::Middleware
|
|
286
291
|
If you want to turn on or off the middleware for certain urls, use the `:only` or `:except` conditions like so:
|
287
292
|
```ruby
|
288
293
|
# conditions can be plain strings or regular expressions, and you can supply only one or an array
|
289
|
-
config.middleware.use WickedPdf::Middleware, {}, :
|
290
|
-
config.middleware.use WickedPdf::Middleware, {}, :
|
294
|
+
config.middleware.use WickedPdf::Middleware, {}, only: '/invoice'
|
295
|
+
config.middleware.use WickedPdf::Middleware, {}, except: [ %r[^/admin], '/secret', %r[^/people/\d] ]
|
291
296
|
```
|
292
|
-
If you use the standard `render :
|
297
|
+
If you use the standard `render pdf: 'some_pdf'` in your app, you will want to exclude those actions from the middleware.
|
293
298
|
|
294
299
|
### Further Reading
|
295
300
|
|
@@ -303,14 +308,19 @@ StackOverflow [questions with the tag "wicked-pdf"](http://stackoverflow.com/que
|
|
303
308
|
|
304
309
|
Now you can use a debug param on the URL that shows you the content of the pdf in plain html to design it faster.
|
305
310
|
|
306
|
-
First of all you must configure the render parameter
|
311
|
+
First of all you must configure the render parameter `show_as_html: params.key?('debug')` and then just use it like you normally would but add "debug" as a GET param in the URL:
|
307
312
|
|
308
|
-
http://localhost:3001/CONTROLLER/X.pdf?debug
|
313
|
+
http://localhost:3001/CONTROLLER/X.pdf?debug
|
309
314
|
|
310
315
|
However, the wicked_pdf_* helpers will use file:/// paths for assets when using :show_as_html, and your browser's cross-domain safety feature will kick in, and not render them. To get around this, you can load your assets like so in your templates:
|
311
316
|
```html
|
312
|
-
<%= params
|
317
|
+
<%= params.key?('debug') ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
|
313
318
|
```
|
319
|
+
|
320
|
+
#### Gotchas
|
321
|
+
|
322
|
+
If one image from your HTML cannot be found (relative or wrong path for ie), others images with right paths **may not** be displayed in the output PDF as well (it seems to be an issue with wkhtmltopdf).
|
323
|
+
|
314
324
|
### Inspiration
|
315
325
|
|
316
326
|
You may have noticed: this plugin is heavily inspired by the PrinceXML plugin [princely](http://github.com/mbleigh/princely/tree/master). PrinceXML's cost was prohibitive for me. So, with a little help from some friends (thanks [jqr](http://github.com/jqr)), I tracked down wkhtmltopdf, and here we are.
|