super-max-pkg 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. checksums.yaml +7 -0
  2. data/super-max-pkg.gemspec +12 -0
  3. data/wicked_pdf-2.8.2/CHANGELOG.md +254 -0
  4. data/wicked_pdf-2.8.2/Gemfile +3 -0
  5. data/wicked_pdf-2.8.2/LICENSE.txt +22 -0
  6. data/wicked_pdf-2.8.2/README.md +504 -0
  7. data/wicked_pdf-2.8.2/Rakefile +58 -0
  8. data/wicked_pdf-2.8.2/gemfiles/5.0.gemfile +8 -0
  9. data/wicked_pdf-2.8.2/gemfiles/5.1.gemfile +8 -0
  10. data/wicked_pdf-2.8.2/gemfiles/5.2.gemfile +9 -0
  11. data/wicked_pdf-2.8.2/gemfiles/6.0.gemfile +10 -0
  12. data/wicked_pdf-2.8.2/gemfiles/6.1.gemfile +11 -0
  13. data/wicked_pdf-2.8.2/gemfiles/7.0.gemfile +11 -0
  14. data/wicked_pdf-2.8.2/generators/wicked_pdf/templates/wicked_pdf.rb +30 -0
  15. data/wicked_pdf-2.8.2/generators/wicked_pdf/wicked_pdf_generator.rb +7 -0
  16. data/wicked_pdf-2.8.2/init.rb +2 -0
  17. data/wicked_pdf-2.8.2/lib/generators/wicked_pdf_generator.rb +7 -0
  18. data/wicked_pdf-2.8.2/lib/wicked_pdf/binary.rb +65 -0
  19. data/wicked_pdf-2.8.2/lib/wicked_pdf/middleware.rb +92 -0
  20. data/wicked_pdf-2.8.2/lib/wicked_pdf/option_parser.rb +230 -0
  21. data/wicked_pdf-2.8.2/lib/wicked_pdf/pdf_helper.rb +128 -0
  22. data/wicked_pdf-2.8.2/lib/wicked_pdf/progress.rb +33 -0
  23. data/wicked_pdf-2.8.2/lib/wicked_pdf/railtie.rb +17 -0
  24. data/wicked_pdf-2.8.2/lib/wicked_pdf/tempfile.rb +43 -0
  25. data/wicked_pdf-2.8.2/lib/wicked_pdf/version.rb +3 -0
  26. data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper/assets.rb +332 -0
  27. data/wicked_pdf-2.8.2/lib/wicked_pdf/wicked_pdf_helper.rb +36 -0
  28. data/wicked_pdf-2.8.2/lib/wicked_pdf.rb +132 -0
  29. data/wicked_pdf-2.8.2/test/fixtures/database.yml +4 -0
  30. data/wicked_pdf-2.8.2/test/fixtures/document_with_long_line.html +16 -0
  31. data/wicked_pdf-2.8.2/test/fixtures/manifest.js +3 -0
  32. data/wicked_pdf-2.8.2/test/fixtures/subdirectory/nested.js +1 -0
  33. data/wicked_pdf-2.8.2/test/fixtures/wicked.css +1 -0
  34. data/wicked_pdf-2.8.2/test/fixtures/wicked.js +1 -0
  35. data/wicked_pdf-2.8.2/test/functional/pdf_helper_test.rb +96 -0
  36. data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_assets_test.rb +252 -0
  37. data/wicked_pdf-2.8.2/test/functional/wicked_pdf_helper_test.rb +28 -0
  38. data/wicked_pdf-2.8.2/test/test_helper.rb +40 -0
  39. data/wicked_pdf-2.8.2/test/unit/wicked_pdf_binary_test.rb +26 -0
  40. data/wicked_pdf-2.8.2/test/unit/wicked_pdf_option_parser_test.rb +133 -0
  41. data/wicked_pdf-2.8.2/test/unit/wicked_pdf_test.rb +100 -0
  42. data/wicked_pdf-2.8.2/test/unit/wkhtmltopdf_location_test.rb +48 -0
  43. data/wicked_pdf-2.8.2/wicked_pdf.gemspec +42 -0
  44. metadata +83 -0
@@ -0,0 +1,504 @@
1
+ # Wicked PDF [![Gem Version](https://badge.fury.io/rb/wicked_pdf.svg)](http://badge.fury.io/rb/wicked_pdf) [![Build Status](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml/badge.svg)](https://github.com/mileszs/wicked_pdf/actions/workflows/ci.yml) [![Code Climate](https://codeclimate.com/github/mileszs/wicked_pdf/badges/gpa.svg)](https://codeclimate.com/github/mileszs/wicked_pdf) [![Open Source Helpers](https://www.codetriage.com/mileszs/wicked_pdf/badges/users.svg)](https://www.codetriage.com/mileszs/wicked_pdf)
2
+
3
+ ## A PDF generation plugin for Ruby on Rails
4
+
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
+
7
+ _Wicked PDF has been verified to work on Ruby versions 2.2 through 3.2; Rails 4 through 7.0_
8
+
9
+ ### Installation
10
+
11
+ Add this to your Gemfile and run `bundle install`:
12
+
13
+ ```ruby
14
+ gem 'wicked_pdf'
15
+ ```
16
+
17
+ Then create the initializer with
18
+
19
+ rails generate wicked_pdf
20
+
21
+ You may also need to add
22
+ ```ruby
23
+ Mime::Type.register "application/pdf", :pdf
24
+ ```
25
+ to `config/initializers/mime_types.rb` in older versions of Rails.
26
+
27
+ Because `wicked_pdf` is a wrapper for [wkhtmltopdf](http://wkhtmltopdf.org/), you'll need to install that, too.
28
+
29
+ The simplest way to install all of the binaries on most Linux or OSX systems is through the gem [wkhtmltopdf-binary](https://github.com/zakird/wkhtmltopdf_binary_gem). Builds for other systems are available [here](https://wkhtmltopdf.org/downloads.html)
30
+ To install that gem, add this:
31
+
32
+ ```ruby
33
+ gem 'wkhtmltopdf-binary'
34
+ ```
35
+
36
+ To your Gemfile and run `bundle install`.
37
+
38
+ This gem currently installs version 0.12.x of `wkhtmltopdf`. Some of the options listed below are specific 0.9 or below, and others are for 0.12 and up.
39
+
40
+ You can see what flags are supported for the current version in [wkhtmltopdf's auto-generated manual](https://wkhtmltopdf.org/usage/wkhtmltopdf.txt)
41
+
42
+ If your wkhtmltopdf executable is not on your webserver's path, you can configure it in an initializer:
43
+
44
+ ```ruby
45
+ WickedPdf.configure do |c|
46
+ c.exe_path = '/usr/local/bin/wkhtmltopdf'
47
+ c.enable_local_file_access = true
48
+ end
49
+ ```
50
+
51
+ For more information about `wkhtmltopdf`, see the project's [homepage](http://wkhtmltopdf.org/).
52
+
53
+ ### Basic Usage
54
+ ```ruby
55
+ class ThingsController < ApplicationController
56
+ def show
57
+ respond_to do |format|
58
+ format.html
59
+ format.pdf do
60
+ render pdf: "file_name" # Excluding ".pdf" extension.
61
+ end
62
+ end
63
+ end
64
+ end
65
+ ```
66
+ ### Usage Conditions - Important!
67
+
68
+ The wkhtmltopdf binary is run outside of your Rails application; therefore, your normal layouts will not work. If you plan to use any CSS, JavaScript, or image files, you must modify your layout so that you provide an absolute reference to these files. The best option for Rails without the asset pipeline is to use the `wicked_pdf_stylesheet_link_tag`, `wicked_pdf_image_tag`, and `wicked_pdf_javascript_include_tag` helpers or to go straight to a CDN (Content Delivery Network) for popular libraries such as jQuery.
69
+
70
+ #### wicked_pdf helpers
71
+ ```html
72
+ <!doctype html>
73
+ <html>
74
+ <head>
75
+ <meta charset='utf-8' />
76
+ <%= wicked_pdf_stylesheet_link_tag "pdf" -%>
77
+ <%= wicked_pdf_javascript_include_tag "number_pages" %>
78
+ </head>
79
+ <body onload='number_pages'>
80
+ <div id="header">
81
+ <%= wicked_pdf_image_tag 'mysite.jpg' %>
82
+ </div>
83
+ <div id="content">
84
+ <%= yield %>
85
+ </div>
86
+ </body>
87
+ </html>
88
+ ```
89
+ Using wicked_pdf_helpers with asset pipeline raises `Asset names passed to helpers should not include the "/assets/" prefix.` error. To work around this, you can use `wicked_pdf_asset_base64` with the normal Rails helpers, but be aware that this will base64 encode your content and inline it in the page. This is very quick for small assets, but large ones can take a long time.
90
+
91
+ ```html
92
+ <!doctype html>
93
+ <html>
94
+ <head>
95
+ <meta charset='utf-8' />
96
+ <%= stylesheet_link_tag wicked_pdf_asset_base64("pdf") %>
97
+ <%= javascript_include_tag wicked_pdf_asset_base64("number_pages") %>
98
+
99
+ </head>
100
+ <body onload='number_pages'>
101
+ <div id="header">
102
+ <%= image_tag wicked_pdf_asset_base64('mysite.jpg') %>
103
+ </div>
104
+ <div id="content">
105
+ <%= yield %>
106
+ </div>
107
+ </body>
108
+ </html>
109
+ ```
110
+
111
+ #### Webpacker usage
112
+
113
+ wicked_pdf supports webpack assets.
114
+
115
+ - Use `wicked_pdf_stylesheet_pack_tag` for stylesheets
116
+ - Use `wicked_pdf_javascript_pack_tag` for javascripts
117
+ - Use `wicked_pdf_asset_pack_path` to access an asset directly, for example: `image_tag wicked_pdf_asset_pack_path("media/images/foobar.png")`
118
+
119
+ #### Asset pipeline usage
120
+
121
+ It is best to precompile assets used in PDF views. This will help avoid issues when it comes to deploying, as Rails serves asset files differently between development and production (`config.assets.compile = false`), which can make it look like your PDFs work in development, but fail to load assets in production.
122
+
123
+ config.assets.precompile += ['blueprint/screen.css', 'pdf.css', 'jquery.ui.datepicker.js', 'pdf.js', ...etc...]
124
+
125
+ #### CDN reference
126
+
127
+ 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.
128
+ ```html
129
+ <!doctype html>
130
+ <html>
131
+ <head>
132
+ <%= javascript_include_tag "http://code.jquery.com/jquery-1.10.0.min.js" %>
133
+ <%= javascript_include_tag "http://code.jquery.com/ui/1.10.3/jquery-ui.min.js" %>
134
+ ```
135
+
136
+ ### Advanced Usage with all available options
137
+
138
+ _NOTE: Certain options are only supported in specific versions of wkhtmltopdf._
139
+
140
+ ```ruby
141
+ class ThingsController < ApplicationController
142
+ def show
143
+ respond_to do |format|
144
+ format.html
145
+ format.pdf do
146
+ render pdf: 'file_name',
147
+ disposition: 'attachment', # default 'inline'
148
+ template: 'things/show',
149
+ locals: {foo: @bar},
150
+ file: "#{Rails.root}/files/foo.erb",
151
+ inline: '<!doctype html><html><head></head><body>INLINE HTML</body></html>',
152
+ layout: 'pdf', # for a pdf.pdf.erb file
153
+ wkhtmltopdf: '/usr/local/bin/wkhtmltopdf', # path to binary
154
+ show_as_html: params.key?('debug'), # allow debugging based on url param
155
+ orientation: 'Landscape', # default Portrait
156
+ page_size: 'A4, Letter, ...', # default A4
157
+ page_height: NUMBER,
158
+ page_width: NUMBER,
159
+ save_to_file: Rails.root.join('pdfs', "#{filename}.pdf"),
160
+ save_only: false, # depends on :save_to_file being set first
161
+ default_protocol: 'http',
162
+ proxy: 'TEXT',
163
+ basic_auth: false # when true username & password are automatically sent from session
164
+ username: 'TEXT',
165
+ password: 'TEXT',
166
+ title: 'Alternate Title', # otherwise first page title is used
167
+ cover: 'URL, Pathname, or raw HTML string',
168
+ dpi: 'dpi',
169
+ encoding: 'TEXT',
170
+ user_style_sheet: 'URL',
171
+ cookie: ['_session_id SESSION_ID'], # could be an array or a single string in a 'name value' format
172
+ post: ['query QUERY_PARAM'], # could be an array or a single string in a 'name value' format
173
+ redirect_delay: NUMBER,
174
+ javascript_delay: NUMBER,
175
+ window_status: 'TEXT', # wait to render until some JS sets window.status to the given string
176
+ image_quality: NUMBER,
177
+ no_pdf_compression: true,
178
+ zoom: FLOAT,
179
+ page_offset: NUMBER,
180
+ book: true,
181
+ default_header: true,
182
+ disable_javascript: false,
183
+ grayscale: true,
184
+ lowquality: true,
185
+ enable_plugins: true,
186
+ disable_internal_links: true,
187
+ disable_external_links: true,
188
+ keep_relative_links: true,
189
+ print_media_type: true,
190
+
191
+ # define as true the key 'disable_local_file_access' or 'enable_local_file_access', not both
192
+ disable_local_file_access: true,
193
+ enable_local_file_access: false, # must be true when using wkhtmltopdf > 0.12.6
194
+ allow: ["#{Rails.root}/public"], # could be an array or a single string
195
+
196
+ disable_smart_shrinking: true,
197
+ use_xserver: true,
198
+ background: false, # background needs to be true to enable background colors to render
199
+ no_background: true,
200
+ no_stop_slow_scripts: false,
201
+ viewport_size: 'TEXT', # available only with use_xserver or patched QT
202
+ extra: '', # directly inserted into the command to wkhtmltopdf
203
+ raise_on_all_errors: nil, # raise error for any stderr output. Such as missing media, image assets
204
+ raise_on_missing_assets: nil, # raise when trying to access a missing asset
205
+ log_level: 'info', # Available values: none, error, warn, or info - only available with wkhtmltopdf 0.12.5+
206
+ quiet: false, # `false` is same as `log_level: 'info'`, `true` is same as `log_level: 'none'`
207
+ outline: { outline: true,
208
+ outline_depth: LEVEL },
209
+ margin: { top: SIZE, # default 10 (mm)
210
+ bottom: SIZE,
211
+ left: SIZE,
212
+ right: SIZE },
213
+ header: { html: { template: 'users/header', # use :template OR :url
214
+ layout: 'pdf_plain', # optional, use 'pdf_plain' for a pdf_plain.html.pdf.erb file, defaults to main layout
215
+ url: 'www.example.com',
216
+ locals: { foo: @bar }},
217
+ center: 'TEXT',
218
+ font_name: 'NAME',
219
+ font_size: SIZE,
220
+ left: 'TEXT',
221
+ right: 'TEXT',
222
+ spacing: REAL,
223
+ line: true,
224
+ content: 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
225
+ footer: { html: { template:'shared/footer', # use :template OR :url
226
+ layout: 'pdf_plain.html', # optional, use 'pdf_plain' for a pdf_plain.html.pdf.erb file, defaults to main layout
227
+ url: 'www.example.com',
228
+ locals: { foo: @bar }},
229
+ center: 'TEXT',
230
+ font_name: 'NAME',
231
+ font_size: SIZE,
232
+ left: 'TEXT',
233
+ right: 'TEXT',
234
+ spacing: REAL,
235
+ line: true,
236
+ content: 'HTML CONTENT ALREADY RENDERED'}, # optionally you can pass plain html already rendered (useful if using pdf_from_string)
237
+ toc: { font_name: "NAME",
238
+ depth: LEVEL,
239
+ header_text: "TEXT",
240
+ header_fs: SIZE,
241
+ text_size_shrink: 0.8,
242
+ l1_font_size: SIZE,
243
+ l2_font_size: SIZE,
244
+ l3_font_size: SIZE,
245
+ l4_font_size: SIZE,
246
+ l5_font_size: SIZE,
247
+ l6_font_size: SIZE,
248
+ l7_font_size: SIZE,
249
+ level_indentation: NUM,
250
+ l1_indentation: NUM,
251
+ l2_indentation: NUM,
252
+ l3_indentation: NUM,
253
+ l4_indentation: NUM,
254
+ l5_indentation: NUM,
255
+ l6_indentation: NUM,
256
+ l7_indentation: NUM,
257
+ no_dots: true,
258
+ disable_dotted_lines: true,
259
+ disable_links: true,
260
+ disable_toc_links: true,
261
+ disable_back_links:true,
262
+ xsl_style_sheet: 'file.xsl'}, # optional XSLT stylesheet to use for styling table of contents
263
+ progress: proc { |output| puts output }, # proc called when console output changes
264
+ delete_temporary_files: true # explicitly delete temporary files, default false
265
+ end
266
+ end
267
+ end
268
+ end
269
+ ```
270
+ By default, it will render without a layout (layout: false) and the template for the current controller and action.
271
+
272
+ #### wkhtmltopdf Binary Options
273
+
274
+ Some of the options above are being passed to `wkhtmltopdf` binary. They can be used to control the options used in Webkit rendering before generating the PDF.
275
+
276
+ Examples of those options are:
277
+
278
+ ```ruby
279
+ print_media_type: true # Passes `--print-media-type`
280
+ no_background: true # Passes `--no-background`
281
+ ```
282
+
283
+ You can see the complete list of options under "Global Options" in wkhtmltopdf usage [docs](http://wkhtmltopdf.org/usage/wkhtmltopdf.txt).
284
+
285
+ ### Super Advanced Usage ###
286
+
287
+ If you need to just create a pdf and not display it:
288
+ ```ruby
289
+ # create a pdf from a string
290
+ pdf = WickedPdf.new.pdf_from_string('<h1>Hello There!</h1>')
291
+
292
+ # create a pdf file from a html file without converting it to string
293
+ # Path must be absolute path
294
+ pdf = WickedPdf.new.pdf_from_html_file('/your/absolute/path/here')
295
+
296
+ # create a pdf from a URL
297
+ pdf = WickedPdf.new.pdf_from_url('https://github.com/mileszs/wicked_pdf')
298
+
299
+ # create a pdf from string using templates, layouts, and content option for header or footer
300
+ pdf = WickedPdf.new.pdf_from_string(
301
+ render_to_string('templates/pdf', layout: 'pdfs/layout_pdf.html'),
302
+ footer: {
303
+ content: render_to_string(
304
+ 'templates/footer',
305
+ layout: 'pdfs/layout_pdf.html'
306
+ )
307
+ }
308
+ )
309
+
310
+ # It is possible to use footer/header templates without a layout, in that case you need to provide a valid HTML document
311
+ pdf = WickedPdf.new.pdf_from_string(
312
+ render_to_string('templates/full_pdf_template'),
313
+ header: {
314
+ content: render_to_string('templates/full_header_template')
315
+ }
316
+ )
317
+
318
+ # or from your controller, using views & templates and all wicked_pdf options as normal
319
+ pdf = render_to_string pdf: "some_file_name", template: "templates/pdf", encoding: "UTF-8"
320
+
321
+ # then save to a file
322
+ save_path = Rails.root.join('pdfs','filename.pdf')
323
+ File.open(save_path, 'wb') do |file|
324
+ file << pdf
325
+ end
326
+
327
+ # you can also track progress on your PDF generation, such as when using it from within a Resque job
328
+ class PdfJob
329
+ def perform
330
+ blk = proc { |output|
331
+ match = output.match(/\[.+\] Page (?<current_page>\d+) of (?<total_pages>\d+)/)
332
+ if match
333
+ current_page = match[:current_page].to_i
334
+ total_pages = match[:total_pages].to_i
335
+ message = "Generated #{current_page} of #{total_pages} pages"
336
+ at current_page, total_pages, message
337
+ end
338
+ }
339
+ WickedPdf.new.pdf_from_string(html, progress: blk)
340
+ end
341
+ end
342
+ ```
343
+ If you need to display utf encoded characters, add this to your pdf views or layouts:
344
+ ```html
345
+ <meta charset="utf-8" />
346
+ ```
347
+ If you need to return a PDF in a controller with Rails in API mode:
348
+ ```ruby
349
+ pdf_html = ActionController::Base.new.render_to_string(template: 'controller_name/action_name', layout: 'pdf')
350
+ pdf = WickedPdf.new.pdf_from_string(pdf_html)
351
+ send_data pdf, filename: 'file.pdf'
352
+ ```
353
+ ### Page Breaks
354
+
355
+ You can control page breaks with CSS.
356
+
357
+ Add a few styles like this to your stylesheet or page:
358
+ ```css
359
+ div.alwaysbreak { page-break-before: always; }
360
+ div.nobreak:before { clear:both; }
361
+ div.nobreak { page-break-inside: avoid; }
362
+ ```
363
+
364
+ ### Page Numbering
365
+
366
+ A bit of javascript can help you number your pages. Create a template or header/footer file with this:
367
+ ```html
368
+ <html>
369
+ <head>
370
+ <script>
371
+ function number_pages() {
372
+ var vars={};
373
+ var x=document.location.search.substring(1).split('&');
374
+ for(var i in x) {var z=x[i].split('=',2);vars[z[0]] = decodeURIComponent(z[1]);}
375
+ var x=['frompage','topage','page','webpage','section','subsection','subsubsection'];
376
+ for(var i in x) {
377
+ var y = document.getElementsByClassName(x[i]);
378
+ for(var j=0; j<y.length; ++j) y[j].textContent = vars[x[i]];
379
+ }
380
+ }
381
+ </script>
382
+ </head>
383
+ <body onload="number_pages()">
384
+ Page <span class="page"></span> of <span class="topage"></span>
385
+ </body>
386
+ </html>
387
+ ```
388
+ Anything with a class listed in "var x" above will be auto-filled at render time.
389
+
390
+ 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]":
391
+ ```ruby
392
+ render pdf: 'filename', header: { right: '[page] of [topage]' }
393
+ ```
394
+ ### Configuration
395
+
396
+ You can put your default configuration, applied to all pdf's at "wicked_pdf.rb" initializer.
397
+
398
+ ### Rack Middleware
399
+
400
+ If you would like to have WickedPdf automatically generate PDF views for all (or nearly all) pages by appending .pdf to the URL, add the following to your Rails app:
401
+ ```ruby
402
+ # in application.rb (Rails3) or environment.rb (Rails2)
403
+ require 'wicked_pdf'
404
+ config.middleware.use WickedPdf::Middleware
405
+ ```
406
+ If you want to turn on or off the middleware for certain URLs, use the `:only` or `:except` conditions like so:
407
+ ```ruby
408
+ # conditions can be plain strings or regular expressions, and you can supply only one or an array
409
+ config.middleware.use WickedPdf::Middleware, {}, only: '/invoice'
410
+ config.middleware.use WickedPdf::Middleware, {}, except: [ %r[^/admin], '/secret', %r[^/people/\d] ]
411
+ ```
412
+ If you use the standard `render pdf: 'some_pdf'` in your app, you will want to exclude those actions from the middleware.
413
+
414
+
415
+ ### Include in an email as an attachment
416
+
417
+ To include a rendered pdf file in an email you can do the following:
418
+
419
+ ```ruby
420
+ attachments['attachment.pdf'] = WickedPdf.new.pdf_from_string(
421
+ render_to_string('link_to_view.pdf.erb', layout: 'pdf')
422
+ )
423
+ ```
424
+
425
+ This will render the pdf to a string and include it in the email. This is very slow so make sure you schedule your email delivery in a job.
426
+
427
+ ### Further Reading
428
+
429
+ Mike Ackerman's post [How To Create PDFs in Rails](https://www.viget.com/articles/how-to-create-pdfs-in-rails)
430
+
431
+ Andreas Happe's post [Generating PDFs from Ruby on Rails](http://www.snikt.net/blog/2012/04/26/wicked-pdf/)
432
+
433
+ JESii's post [WickedPDF, wkhtmltopdf, and Heroku...a tricky combination](http://www.nubyrubyrailstales.com/2013/06/wickedpdf-wkhtmltopdf-and-herokua.html)
434
+
435
+ Berislav Babic's post [Send PDF attachments from Rails with WickedPdf and ActionMailer](http://berislavbabic.com/send-pdf-attachments-from-rails-with-wickedpdf-and-actionmailer/)
436
+
437
+ Corsego's 2021 post [Complete guide to generating PDFs with gem wicked_pdf](https://blog.corsego.com/gem-wicked-pdf)
438
+
439
+ PDFTron's post [How to Generate PDFs With Ruby on Rails](https://www.pdftron.com/blog/rails/how-to-generate-pdf-with-ruby-on-rails/)
440
+
441
+ StackOverflow [questions with the tag "wicked-pdf"](http://stackoverflow.com/questions/tagged/wicked-pdf)
442
+
443
+ ### Screencasts
444
+
445
+ * SupeRails Screencast [EN]
446
+
447
+ [![Ruby on Rails #17 generate, save, send PDFs with gem wicked_pdf](https://i3.ytimg.com/vi/tFvtwEmW-GE/hqdefault.jpg)](https://youtu.be/tFvtwEmW-GE)
448
+
449
+ * codigofacilito Screencast [ES]
450
+
451
+ [![Generar PDF con Ruby on Rails - Tutorial](https://i3.ytimg.com/vi/jeWM_gusmJc/hqdefault.jpg)](https://youtu.be/jeWM_gusmJc)
452
+
453
+ ### Debugging
454
+
455
+ 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.
456
+
457
+ 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:
458
+
459
+ http://localhost:3001/CONTROLLER/X.pdf?debug
460
+
461
+ 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:
462
+ ```html
463
+ <%= params.key?('debug') ? image_tag('foo') : wicked_pdf_image_tag('foo') %>
464
+ ```
465
+
466
+ #### Gotchas
467
+
468
+ If one image from your HTML cannot be found (relative or wrong path for example), others images with right paths **may not** be displayed in the output PDF as well (it seems to be an issue with wkhtmltopdf).
469
+
470
+ wkhtmltopdf may render at different resolutions on different platforms. For example, Linux prints at 75 dpi (native for WebKit) while on Windows it's at the desktop's DPI (which is normally 96 dpi). [Use `:zoom => 0.78125`](https://github.com/wkhtmltopdf/wkhtmltopdf/issues/2184) (75/96) to match Linux rendering to Windows.
471
+
472
+ ### Security considerations
473
+
474
+ WickedPdf renders page content on the server by saving HTML and assets to temporary files on disk, then executing `wkhtmltopdf` to convert that HTML to a PDF file.
475
+
476
+ It is highly recommended if you allow user-generated HTML/CSS/JS to be converted to PDF, you sanitize it first, or at least disallow requesting content from internal IP addresses and hostnames.
477
+
478
+ For example, these could potentially leak internal AWS metadata:
479
+ ```html
480
+ <iframe src="http://169.254.169.254/latest/meta-data/"></iframe>
481
+ <object data="http://169.254.169.254/latest/meta-data/" type="text/html">
482
+ ```
483
+
484
+ Thank you to Adam Gold from [Snyk](https://snyk.io) for reporting this.
485
+ We are considering adding host allow & block lists and/or potentially HTML element sanitizing.
486
+ Please open an issue or PR to help us out with this.
487
+
488
+ ### Inspiration
489
+
490
+ 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.
491
+
492
+ ### Contributing
493
+
494
+ 1. Fork it
495
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
496
+ 3. Run the test suite and check the output (`rake`)
497
+ 4. Add tests for your feature or fix (please)
498
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
499
+ 6. Push to the branch (`git push origin my-new-feature`)
500
+ 7. Create new Pull Request
501
+
502
+ ### Awesome Peoples
503
+
504
+ Also, thanks to [unixmonkey](https://github.com/Unixmonkey), [galdomedia](http://github.com/galdomedia), [jcrisp](http://github.com/jcrisp), [lleirborras](http://github.com/lleirborras), [tiennou](http://github.com/tiennou), and everyone else for all their hard work and patience with my delays in merging in their enhancements.
@@ -0,0 +1,58 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rdoc/task'
4
+ require 'rails/version'
5
+ require 'bundler/gem_tasks'
6
+
7
+ desc 'Default: run unit tests.'
8
+ task :default => %i[setup_and_run_tests rubocop]
9
+
10
+ desc 'Test the wicked_pdf plugin.'
11
+ Rake::TestTask.new(:test) do |t|
12
+ t.libs << 'lib'
13
+ t.libs << 'test'
14
+ t.pattern = 'test/**/*_test.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ desc 'Run RuboCop'
19
+ task :rubocop do
20
+ require 'rubocop/rake_task'
21
+ RuboCop::RakeTask.new
22
+ end
23
+
24
+ desc 'Setup and run all tests'
25
+ task :setup_and_run_tests do
26
+ Rake::Task[:dummy_generate].invoke unless File.exist?('test/dummy/config/environment.rb')
27
+ Rake::Task[:test].invoke
28
+ end
29
+
30
+ desc 'Generate dummy application for test cases'
31
+ task :dummy_generate do
32
+ Rake::Task[:dummy_remove].invoke
33
+ puts 'Creating dummy application to run tests'
34
+ system('rails new test/dummy --database=sqlite3')
35
+ system('touch test/dummy/db/schema.rb')
36
+ FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
37
+ FileUtils.rm_r Dir.glob('test/dummy/test/*')
38
+
39
+ # rails 6 needs this to be present before start:
40
+ FileUtils.mkdir_p('test/dummy/app/assets/config')
41
+ FileUtils.mkdir_p('test/dummy/app/assets/javascripts')
42
+ FileUtils.cp 'test/fixtures/manifest.js', 'test/dummy/app/assets/config/'
43
+ FileUtils.cp 'test/fixtures/wicked.js', 'test/dummy/app/assets/javascripts/'
44
+ end
45
+
46
+ desc 'Remove dummy application'
47
+ task :dummy_remove do
48
+ FileUtils.rm_r Dir.glob('test/dummy/')
49
+ end
50
+
51
+ desc 'Generate documentation for the wicked_pdf gem.'
52
+ RDoc::Task.new(:rdoc) do |rdoc|
53
+ rdoc.rdoc_dir = 'rdoc'
54
+ rdoc.title = 'WickedPdf'
55
+ rdoc.options << '--line-numbers' << '--inline-source'
56
+ rdoc.rdoc_files.include('README.md')
57
+ rdoc.rdoc_files.include('lib/**/*.rb')
58
+ end
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.0.0'
4
+ gem 'rdoc'
5
+ gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
6
+ gem 'sqlite3', '~> 1.3.6'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '~> 5.1.0'
4
+ gem 'rdoc'
5
+ gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
6
+ gem 'sqlite3', '~> 1.3.6'
7
+
8
+ gemspec path: '../'
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 5.2
4
+ gem 'rails', '~> 5.2'
5
+ gem 'rdoc'
6
+ gem 'sprockets', '~>3.0' # v4 strips newlines from assets causing tests to fail
7
+ gem 'sqlite3', '~> 1.3.6'
8
+
9
+ gemspec path: '../'
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 6.0
4
+ gem 'bundler', '~>2'
5
+ gem 'rails', '~>6.0.1'
6
+ gem 'rdoc'
7
+ gem 'sprockets', '~>3.0'
8
+ gem 'sqlite3', '~> 1.4'
9
+
10
+ gemspec path: '../'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 6.1
4
+ gem 'bundler', '~>2'
5
+ gem 'rails', '~>6.1.0'
6
+ gem 'webpacker'
7
+ gem 'rdoc'
8
+ gem 'sprockets', '~>3.0'
9
+ gem 'sqlite3', '~> 1.4'
10
+
11
+ gemspec :path => '../'
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'bootsnap' # required to run `rake test` in Rails 7.0
4
+ gem 'bundler', '~>2'
5
+ gem 'rails', '~>7.0.0'
6
+ gem 'sprockets-rails'
7
+ gem 'rdoc'
8
+ gem 'sprockets', '~>3.0'
9
+ gem 'sqlite3', '~> 1.4'
10
+
11
+ gemspec :path => '../'
@@ -0,0 +1,30 @@
1
+ # WickedPDF Global Configuration
2
+ #
3
+ # Use this to set up shared configuration options for your entire application.
4
+ # Any of the configuration options shown here can also be applied to single
5
+ # models by passing arguments to the `render :pdf` call.
6
+ #
7
+ # To learn more, check out the README:
8
+ #
9
+ # https://github.com/mileszs/wicked_pdf/blob/master/README.md
10
+
11
+ WickedPdf.configure do |config|
12
+ # Path to the wkhtmltopdf executable: This usually isn't needed if using
13
+ # one of the wkhtmltopdf-binary family of gems.
14
+ # config.exe_path = '/usr/local/bin/wkhtmltopdf'
15
+ # or
16
+ # config.exe_path = Gem.bin_path('wkhtmltopdf-binary', 'wkhtmltopdf')
17
+
18
+ # Needed for wkhtmltopdf 0.12.6+ to use many wicked_pdf asset helpers
19
+ # config.enable_local_file_access = true
20
+
21
+ # Layout file to be used for all PDFs
22
+ # (but can be overridden in `render :pdf` calls)
23
+ # config.layout = 'pdf.html'
24
+
25
+ # Using wkhtmltopdf without an X server can be achieved by enabling the
26
+ # 'use_xvfb' flag. This will wrap all wkhtmltopdf commands around the
27
+ # 'xvfb-run' command, in order to simulate an X server.
28
+ #
29
+ # config.use_xvfb = true
30
+ end
@@ -0,0 +1,7 @@
1
+ class WickedPdfGenerator < Rails::Generator::Base
2
+ def manifest
3
+ record do |m|
4
+ m.file 'wicked_pdf.rb', 'config/initializers/wicked_pdf.rb'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,2 @@
1
+ require 'wicked_pdf'
2
+ require 'wicked_pdf_tempfile'