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.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -1
  3. data/.travis.yml +13 -3
  4. data/Gemfile +1 -1
  5. data/README.md +152 -142
  6. data/Rakefile +24 -12
  7. data/gemfiles/2.3.gemfile +2 -0
  8. data/gemfiles/3.1.gemfile +3 -2
  9. data/gemfiles/3.2.gemfile +3 -2
  10. data/gemfiles/4.0.gemfile +2 -2
  11. data/gemfiles/4.1.gemfile +6 -0
  12. data/gemfiles/4.2.gemfile +6 -0
  13. data/gemfiles/rails_edge.gemfile +3 -3
  14. data/generators/wicked_pdf/templates/wicked_pdf.rb +19 -3
  15. data/generators/wicked_pdf/wicked_pdf_generator.rb +1 -1
  16. data/lib/generators/wicked_pdf_generator.rb +2 -2
  17. data/lib/wicked_pdf.rb +241 -212
  18. data/lib/wicked_pdf/middleware.rb +6 -7
  19. data/lib/wicked_pdf/pdf_helper.rb +53 -53
  20. data/lib/wicked_pdf/railtie.rb +14 -14
  21. data/lib/wicked_pdf/tempfile.rb +2 -2
  22. data/lib/wicked_pdf/version.rb +2 -2
  23. data/lib/wicked_pdf/wicked_pdf_helper.rb +30 -15
  24. data/test/functional/pdf_helper_test.rb +5 -5
  25. data/test/functional/wicked_pdf_helper_assets_test.rb +35 -8
  26. data/test/functional/wicked_pdf_helper_test.rb +2 -2
  27. data/test/test_helper.rb +10 -5
  28. data/test/unit/wicked_pdf_test.rb +90 -57
  29. data/wicked_pdf.gemspec +5 -4
  30. metadata +20 -72
  31. data/test/dummy/README.rdoc +0 -261
  32. data/test/dummy/Rakefile +0 -7
  33. data/test/dummy/app/assets/javascripts/application.js +0 -15
  34. data/test/dummy/app/assets/stylesheets/application.css +0 -13
  35. data/test/dummy/app/controllers/application_controller.rb +0 -3
  36. data/test/dummy/app/helpers/application_helper.rb +0 -2
  37. data/test/dummy/app/mailers/.gitkeep +0 -0
  38. data/test/dummy/app/models/.gitkeep +0 -0
  39. data/test/dummy/app/views/layouts/application.html.erb +0 -14
  40. data/test/dummy/config.ru +0 -4
  41. data/test/dummy/config/application.rb +0 -59
  42. data/test/dummy/config/boot.rb +0 -10
  43. data/test/dummy/config/database.yml +0 -25
  44. data/test/dummy/config/environment.rb +0 -5
  45. data/test/dummy/config/environments/development.rb +0 -37
  46. data/test/dummy/config/environments/production.rb +0 -67
  47. data/test/dummy/config/environments/test.rb +0 -37
  48. data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
  49. data/test/dummy/config/initializers/inflections.rb +0 -15
  50. data/test/dummy/config/initializers/mime_types.rb +0 -5
  51. data/test/dummy/config/initializers/secret_token.rb +0 -7
  52. data/test/dummy/config/initializers/session_store.rb +0 -8
  53. data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
  54. data/test/dummy/config/locales/en.yml +0 -5
  55. data/test/dummy/config/routes.rb +0 -58
  56. data/test/dummy/db/test.sqlite3 +0 -0
  57. data/test/dummy/lib/assets/.gitkeep +0 -0
  58. data/test/dummy/log/.gitkeep +0 -0
  59. data/test/dummy/public/404.html +0 -26
  60. data/test/dummy/public/422.html +0 -26
  61. data/test/dummy/public/500.html +0 -25
  62. data/test/dummy/public/favicon.ico +0 -0
  63. data/test/dummy/script/rails +0 -6
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54d0ec248323c907fe336b0dea9afff757737f6d
4
- data.tar.gz: 35626a59f71132ef14fb866f453e23998e1c1982
3
+ metadata.gz: dd7dae1230ac2e120e6ca1cb235a8f21465df966
4
+ data.tar.gz: c66399843e25433bc83ac7970ff392f2a217bf95
5
5
  SHA512:
6
- metadata.gz: 41d0c2d5e21c6b1086c425e0e4ebe65f09421694f054435b0d97d9d10622dd493a6dc89c606bbbe6afe9a6261a7639d1545efeb7a0faae1d157518c8e6654886
7
- data.tar.gz: 38cf8a6e92c561713effa3e3f28259a19b8252f9d9810b46f9ee6c31801f895ffbe229748ad10dc81bd215c2db79b78aba8896fbdb81a735d0813c30d83ac077
6
+ metadata.gz: 86a57ed7f58c19916f48c8cfc98074c5e6cb3ca060c1563abbb2c62e2c0eecefeaba635502ece68c870be7b4049422ef7fd326d59507a6a8709d3938def96491
7
+ data.tar.gz: e97feccdf135d2e74d2d14e9ba1e944c130ed631c27a2f18c46e5be1f6804ac439e75755a0a3ddeffffe877d33547c07c76f13980b5b42d0eda45f243f98e399
data/.gitignore CHANGED
@@ -16,6 +16,6 @@ test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
18
  *.swp
19
- test/dummy/log/*.log
19
+ test/dummy/**/*
20
20
  gemfiles/*.lock
21
21
  .DS_Store
@@ -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.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
@@ -1,3 +1,3 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  gemspec
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://code.google.com/p/wkhtmltopdf/) 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 take care of the hard stuff.
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 and 1.9.2; Rails 2 and Rails 3_
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
- First, be sure to install [wkhtmltopdf](http://code.google.com/p/wkhtmltopdf/).
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 'wkhtmltopdf-binary'
14
+ gem 'wicked_pdf'
18
15
  ```
19
16
 
20
- To your Gemfile.
17
+ Then create the initializer with
21
18
 
22
- If your wkhtmltopdf executable is not on your webserver's path, configure it in an initializer:
19
+ rails generate wicked_pdf
23
20
 
21
+ You may also need to add
24
22
  ```ruby
25
- WickedPdf.config = {
26
- :exe_path => '/usr/local/bin/wkhtmltopdf'
27
- }
23
+ Mime::Type.register "application/pdf", :pdf
28
24
  ```
29
- Note that versions before 0.9.0 [have problems](http://code.google.com/p/wkhtmltopdf/issues/detail?id=82&q=vodnik) on some machines with reading/writing to streams.
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
- script/plugin install git://github.com/mileszs/wicked_pdf.git
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
- or add this to your Gemfile:
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 'wicked_pdf'
33
+ gem 'wkhtmltopdf-binary'
45
34
  ```
46
35
 
47
- You may also need to add
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
- Mime::Type.register "application/pdf", :pdf
41
+ WickedPdf.config = {
42
+ exe_path: '/usr/local/bin/wkhtmltopdf'
43
+ }
50
44
  ```
51
- to `config/initializers/mime_types.rb`
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 :pdf => "file_name"
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
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
73
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
74
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
67
+ <!doctype html>
68
+ <html>
75
69
  <head>
76
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
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
- <!DOCTYPE...
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 :pdf => 'file_name',
114
- :disposition => 'attachment', # default 'inline'
115
- :template => 'things/show.pdf.erb',
116
- :file => "#{Rails.root}/files/foo.erb"
117
- :layout => 'pdf.html', # use 'pdf.html' for a pdf.html.erb file
118
- :wkhtmltopdf => '/usr/local/bin/wkhtmltopdf', # path to binary
119
- :show_as_html => params[:debug].present?, # allow debugging based on url param
120
- :orientation => 'Landscape', # default Portrait
121
- :page_size => 'A4, Letter, ...', # default A4
122
- :save_to_file => Rails.root.join('pdfs', "#{filename}.pdf"),
123
- :save_only => false, # depends on :save_to_file being set first
124
- :proxy => 'TEXT',
125
- :basic_auth => false # when true username & password are automatically sent from session
126
- :username => 'TEXT',
127
- :password => 'TEXT',
128
- :cover => 'URL, Pathname, or raw HTML string',
129
- :dpi => 'dpi',
130
- :encoding => 'TEXT',
131
- :user_style_sheet => 'URL',
132
- :cookie => ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
133
- :post => ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
134
- :redirect_delay => NUMBER,
135
- :javascript_delay => NUMBER,
136
- :image_quality => NUMBER,
137
- :zoom => FLOAT,
138
- :page_offset => NUMBER,
139
- :javascript_delay => NUMBER,
140
- :book => true,
141
- :default_header => true,
142
- :disable_javascript => false,
143
- :grayscale => true,
144
- :lowquality => true,
145
- :enable_plugins => true,
146
- :disable_internal_links => true,
147
- :disable_external_links => true,
148
- :print_media_type => true,
149
- :disable_smart_shrinking => true,
150
- :use_xserver => true,
151
- :no_background => true,
152
- :viewport_size => 'TEXT' # available only with use_xserver or patched QT
153
- :extra => '' # directly inserted into the command to wkhtmltopdf
154
- :margin => {:top => SIZE, # default 10 (mm)
155
- :bottom => SIZE,
156
- :left => SIZE,
157
- :right => SIZE},
158
- :header => {:html => { :template => 'users/header.pdf.erb', # use :template OR :url
159
- :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
160
- :url => 'www.example.com',
161
- :locals => { :foo => @bar }},
162
- :center => 'TEXT',
163
- :font_name => 'NAME',
164
- :font_size => SIZE,
165
- :left => 'TEXT',
166
- :right => 'TEXT',
167
- :spacing => REAL,
168
- :line => true,
169
- :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
170
- :footer => {:html => { :template => 'shared/footer.pdf.erb', # use :template OR :url
171
- :layout => 'pdf_plain.html', # optional, use 'pdf_plain.html' for a pdf_plain.html.erb file, defaults to main layout
172
- :url => 'www.example.com',
173
- :locals => { :foo => @bar }},
174
- :center => 'TEXT',
175
- :font_name => 'NAME',
176
- :font_size => SIZE,
177
- :left => 'TEXT',
178
- :right => 'TEXT',
179
- :spacing => REAL,
180
- :line => true,
181
- :content => 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
182
- :toc => {:font_name => "NAME",
183
- :depth => LEVEL,
184
- :header_text => "TEXT",
185
- :header_fs => SIZE,
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
- :l1_indentation => NUM,
194
- :l2_indentation => NUM,
195
- :l3_indentation => NUM,
196
- :l4_indentation => NUM,
197
- :l5_indentation => NUM,
198
- :l6_indentation => NUM,
199
- :l7_indentation => NUM,
200
- :no_dots => true,
201
- :disable_links => true,
202
- :disable_back_links => true},
203
- :outline => {:outline => true,
204
- :outline_depth => LEVEL}
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 (:layout => false) and the template for the current controller and action.
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', :layout => 'pdfs/layout_pdf'),
226
- :footer => {
227
- :content => render_to_string(:layout => 'pdfs/layout_pdf')
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 => "some_file_name"
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 http-equiv="content-type" content="text/html; charset=utf-8" />
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]] = unescape(z[1]);}
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 :pdf => 'filename', :header => { :right => '[page] of [topage]' }
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, {}, :only => '/invoice'
290
- config.middleware.use WickedPdf::Middleware, {}, :except => [ %r[^/admin], '/secret', %r[^/people/\d] ]
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 :pdf => 'some_pdf'` in your app, you will want to exclude those actions from the middleware.
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 ":show_as_html => params[:debug]" and then just use it like normally but adding "debug=1" as a param:
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=1
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[:debug].present? ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
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.