pdfgen 0.4.2 → 0.8.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8e28174877f0b28647fd1653c187ecf4bd0fe3b7
4
- data.tar.gz: 98e2bbed6e8f2d4bf6252432f612e2cabee4540f
3
+ metadata.gz: bcdeca0b0cd11c902176aef409ebde2b2be733e3
4
+ data.tar.gz: 2fff00de1528642236c64bda3fc616b6fe80b838
5
5
  SHA512:
6
- metadata.gz: a47ffc3ad2f07bee137731ec1187da17e3c5b601ba0797ff6cf3b6613037f096bf8ca217dcf23165fa3a9a16a24a861e810c281dab84279b972bf332247351ac
7
- data.tar.gz: 4bdb05250de0ec74f63dbf913387957add058f2c82d693c5a12a5237cf324389631da9bb848d82f288a529f74117addaca8c73519937c927cbcb9c88aff1434e
6
+ metadata.gz: d80dc52b63bc498f8183ffec8d8d5b554afd21a1ebad8d7e1206c6ade6628ac3a7b45f93ba0d44bd72ec5a9521b322b5064533b767617fd027ad505ab8346e9f
7
+ data.tar.gz: c27b05d3d6a47f0ce0d79bd65949ae41b879dd9d8ba15fb650257f0c6ba1d59c8ca8f6ddb933454f30430e7e678850f9ccef59ad6f8d1a2e8df450dd5cb0a1d9
@@ -1,3 +1,53 @@
1
+ ## Pdfgen 0.8.1 (November 30, 2020)
2
+
3
+ * Handle deprecation of emulateMedia function.
4
+
5
+ This was submitted by https://github.com/maokomioko in
6
+ https://github.com/romaimperator/pdfgen/pull/2. Thanks for your contribution!
7
+
8
+ ## Pdfgen 0.8.0 (December 17, 2019)
9
+
10
+ * Allow using a `file://` path as a URL for PDFs
11
+
12
+ This was submitted by https://github.com/maokomioko in
13
+ https://github.com/romaimperator/pdfgen/pull/1. Thanks for your contribution!
14
+
15
+ ## Pdfgen 0.7.0 (June 14, 2019)
16
+
17
+ * Revert to using setContent but require Puppeteer >= 1.11.0.
18
+
19
+ This version of Puppeteer added support to setContent for waiting until browser
20
+ events fire. The original reason for transitioning away from setContent was lack
21
+ of that feature and navigating to a data URL is limited to a maximum of 2 megabytes
22
+ of HTML as that is Chromium's URL length limit.
23
+
24
+ ## Pdfgen 0.6.0 (June 14, 2019)
25
+
26
+ * Use capture3 to also capture stderror which is where Node error messages are output.
27
+
28
+ This allows Pdfgen to include the error from Node in the exception that is raised.
29
+
30
+ ## Pdfgen 0.5.0 (September 3, 2018)
31
+
32
+ * Changes how the wait for timeout works slightly.
33
+
34
+ This new way starts the wait prior to putting the HTML in the page. Now that we can
35
+ utilize the waitUntil navigation feature in Puppeteer, we might as well start the
36
+ clock before waiting for that amount of time. This way, the maximum wait time should
37
+ be roughly the timeout instead of the timeout + how long the page takes to load.
38
+
39
+ * Changes how static HTML is put into the page.
40
+
41
+ This new method allows us to use the navigation wait helpers so there should be
42
+ almost no need for timeout waiting if passing Pdfgen HTML instead of a URL.
43
+
44
+ Sadly, this still does not load assets on the page so inlining your assets is still
45
+ required.
46
+
47
+ * Moves emulateMedia and setViewport steps to be before setting content or navigation
48
+ so that the browser won't need to rerender the content and hopefully we improve
49
+ performance some.
50
+
1
51
  ## Pdfgen 0.4.2 (June 8, 2018)
2
52
 
3
53
  * Adds checking of minimum Node version required.
data/README.md CHANGED
@@ -4,7 +4,7 @@ A tool for creating PDFs using [Puppeteer](https://github.com/GoogleChrome/puppe
4
4
  # Dependencies
5
5
  This gem requires:
6
6
  * Node v7.6 or greater
7
- * Puppeteer (tested with v1.3.0)
7
+ * Puppeteer v1.11.0 or greater
8
8
 
9
9
  ### OSX (Homebrew)
10
10
  To install node on OSX you can use Homebrew:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.2
1
+ 0.8.1
@@ -41,15 +41,14 @@ stdin.on('end', function () {
41
41
  (async() => {
42
42
  const browser = await puppeteer.launch(launch_options);
43
43
  const page = await browser.newPage();
44
-
45
- if (typeof url !== 'undefined' && url) {
46
- await page.goto(url, url_options);
47
- } else {
48
- await page.setContent(html);
49
- }
44
+ let wait_promise = null;
50
45
 
51
46
  if (typeof media_type !== 'undefined' && media_type) {
52
- await page.emulateMedia(media_type);
47
+ if (typeof page.emulateMedia !== 'undefined') {
48
+ await page.emulateMedia(media_type);
49
+ } else {
50
+ await page.emulateMediaType(media_type);
51
+ }
53
52
  }
54
53
 
55
54
  if (typeof viewport_options !== 'undefined' && viewport_options) {
@@ -57,7 +56,21 @@ stdin.on('end', function () {
57
56
  }
58
57
 
59
58
  if (typeof wait_for_timeout !== 'undefined' && wait_for_timeout) {
60
- await page.waitFor(wait_for_timeout);
59
+ wait_promise = page.waitFor(wait_for_timeout);
60
+ }
61
+
62
+ if (typeof url !== 'undefined' && url) {
63
+ await page.goto(url, url_options);
64
+ } else {
65
+ await page.setContent(html, { waitUntil: ["networkidle0", "load"] });
66
+ }
67
+
68
+ // If we were given a wait timeout, we should wait for the rest of the timeout now. That way,
69
+ // the timeout will act as a minimum amount of time to wait for the page. If it's greater than
70
+ // how long the waitUntil idle took, it will wait for the extra time. If it is shorter than how
71
+ // long the page actually needs, then it will not add any time.
72
+ if (typeof wait_promise !== 'undefined' && wait_promise) {
73
+ await wait_promise;
61
74
  }
62
75
 
63
76
  if (typeof debug_mode === 'undefined') {
@@ -13,7 +13,7 @@ MAKE_PDF_COMMAND = File.expand_path('../javascript_bin/make_pdf.js', __FILE__)
13
13
 
14
14
  class Pdfgen
15
15
  def initialize(html_or_url)
16
- if html_or_url =~ /\Ahttp/
16
+ if html_or_url =~ /\Ahttp|\Afile/
17
17
  @url = html_or_url
18
18
  @html = nil
19
19
  else
@@ -74,21 +74,22 @@ class Pdfgen
74
74
  end
75
75
 
76
76
  pdf_output = nil
77
+ error_output = nil
77
78
  status = nil
78
79
  if @html
79
80
  file = Tempfile.new('input_html')
80
81
  file.write(@html)
81
82
  file.close
82
- pdf_output, status = Open3.capture2(MAKE_PDF_COMMAND, file.path, stdin_data: stdin_options.to_json)
83
+ pdf_output, error_output, status = Open3.capture3(MAKE_PDF_COMMAND, file.path, stdin_data: stdin_options.to_json)
83
84
  file.unlink
84
85
  else
85
86
  stdin_options = stdin_options.merge(url: @url)
86
87
  stdin_options = stdin_options.merge(url_options: @url_options)
87
- pdf_output, status = Open3.capture2(MAKE_PDF_COMMAND, stdin_data: stdin_options.to_json)
88
+ pdf_output, error_output, status = Open3.capture3(MAKE_PDF_COMMAND, stdin_data: stdin_options.to_json)
88
89
  end
89
90
 
90
91
  unless status.success?
91
- raise 'There was an unknown error running node to create the pdf. Check your logs for output that might assist in debugging.'
92
+ raise "This error was encountered running node to create the pdf: #{error_output}"
92
93
  end
93
94
  unless pdf_output
94
95
  raise 'There was an error creating the temporary file used to pass the HTML to node.'
@@ -98,4 +99,4 @@ class Pdfgen
98
99
  end
99
100
 
100
101
 
101
- # Use a new API that uses method chaining to configure the PDF and that queues up strings to put in a js file to run puppeteer
102
+ # Use a new API that uses method chaining to configure the PDF and that queues up strings to put in a js file to run puppeteer
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pdfgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Fox
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-08 00:00:00.000000000 Z
11
+ date: 2020-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -58,7 +58,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
58
  version: '0'
59
59
  requirements: []
60
60
  rubyforge_project:
61
- rubygems_version: 2.6.14
61
+ rubygems_version: 2.5.2.3
62
62
  signing_key:
63
63
  specification_version: 4
64
64
  summary: Generate PDFs using Puppeteer and headless Chrome