pdf_gem 1.0.3 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -0
- data/lib/pdf_gem.rb +2 -2
- data/lib/pdf_gem/version.rb +1 -1
- data/lib/pdf_generator.js +9 -2
- data/lib/renderer.rb +24 -14
- data/lib/tmp/7d5de811543153dac4c2146cdd00647d71bced27665b7463437d2dc30ad6efb08bf5c4625768b483.pdf +0 -0
- data/lib/tmp/b3f46a28a790a1b1baa1a8e3ba73e23203f03207d612f861060604b7a6fa4bcb33d1f42058264233.pdf +0 -0
- data/lib/tmp/yt2g01tvjh8p6qu2dpk950s443kckym9ke2s6opv.html +13 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c41cdda0a69ee5b16151416030262480d05d1ff048831ffe2d719272f0276ef3
|
4
|
+
data.tar.gz: 132c82ddf85d0787d34cdea55bf3f6934987693e6f23a52f48298ae6b4afbf69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cad0d93667e53aba5f93cb2426fdee0afccd2299b00c950d0f4e53fb7b1005dc2576564b8dc28b9f26f47b94903272b26a7b9a6fb4bd1862c905b25b1bc66ca9
|
7
|
+
data.tar.gz: 49528c9d199b14e375be3c386b7e2bbc1d66f8dbf83e0ab752e355cd9d474671d11da6a084669d1de137670f8e0ed41f975c4c7d3902472465d79dcc86ec3956
|
data/README.md
CHANGED
@@ -70,6 +70,12 @@ PdfGem.pdf_from_string(options)
|
|
70
70
|
|
71
71
|
- `options` <[Object]> Options object which might have the following properties:
|
72
72
|
- `url` <[string]> (Used only for PdfGem.pdf_from_url) This is the url to render.
|
73
|
+
- `timeout` <[number]> Maximum navigation time in ms, default is 3000 ms.
|
74
|
+
- `waitUntil` <[string]|[Array]<[string]>> When to consider navigation succeeded, defaults to `load`. Given an array of event strings, navigation is considered to be successful after all events have been fired. Events can be either:
|
75
|
+
- `load` - consider navigation to be finished when the `load` event is fired.
|
76
|
+
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
77
|
+
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
78
|
+
- `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
73
79
|
- `html` <[string]> (Used only for PdfGem.pdf_from_string) This is the html string to render.
|
74
80
|
- `disposition` <[string]> (Use only for controller render) Disposition string (inline/attachment).
|
75
81
|
- `formats` <[string]> (Use only for controller render) Force to load view of a particular format (pdf, html, xml).
|
data/lib/pdf_gem.rb
CHANGED
@@ -16,7 +16,7 @@ module PdfGem
|
|
16
16
|
end
|
17
17
|
else
|
18
18
|
raise stderr.present? ? stderr : "error"
|
19
|
-
end
|
19
|
+
end
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.pdf_from_string(params)
|
@@ -26,7 +26,7 @@ module PdfGem
|
|
26
26
|
File.open(html_file, "w+") do |f|
|
27
27
|
f.write(params[:html])
|
28
28
|
end
|
29
|
-
params[:url] = "file
|
29
|
+
params[:url] = "file://#{html_file}"
|
30
30
|
result = self.pdf_from_url(params)
|
31
31
|
File.delete(html_file) if File.exist?(html_file)
|
32
32
|
return result
|
data/lib/pdf_gem/version.rb
CHANGED
data/lib/pdf_generator.js
CHANGED
@@ -6,12 +6,19 @@ const path = require('path');
|
|
6
6
|
(async () => {
|
7
7
|
|
8
8
|
var stdinBuffer = fs.readFileSync(0);
|
9
|
-
|
9
|
+
|
10
|
+
var tmp = path.join(path.dirname(__filename), 'tmp');
|
11
|
+
|
12
|
+
if (!fs.existsSync(tmp)){
|
13
|
+
fs.mkdirSync(tmp);
|
14
|
+
}
|
15
|
+
|
16
|
+
const filename = path.join(tmp, crypto.randomBytes(40).toString('hex')+ '.pdf');
|
10
17
|
const browser = await puppeteer.launch();
|
11
18
|
try{
|
12
19
|
const params = {...JSON.parse(Buffer.from(stdinBuffer.toString(), 'base64').toString('utf-8')), ...{path: filename}};
|
13
20
|
const page = await browser.newPage();
|
14
|
-
await page.goto(params.url, {waitUntil: '
|
21
|
+
await page.goto(params.url, {waitUntil: (params.waitUntil != null ? params.waitUntil : 'load'), timeout: (params.timeout == null ? 30000 : params.timeout)});
|
15
22
|
await page.pdf(params);
|
16
23
|
process.stdout.write(filename)
|
17
24
|
}
|
data/lib/renderer.rb
CHANGED
@@ -1,17 +1,27 @@
|
|
1
|
-
module PdfGem
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
send_data PdfGem::pdf_from_string(params), type: Mime[:pdf], disposition: (params[:disposition].present? ? params[:disposition] : 'inline'), :filename => options[:filename]
|
6
|
-
end
|
7
|
-
|
8
|
-
ActionController::Renderers.add :pdf2 do |template, options|
|
9
|
-
params = options.except(:prefixes, :template, :disposition, :url, :html, :filename, :formats)
|
10
|
-
params[:html] = render_to_string(:action => (template.present? ? template : options.template), formats: options[:formats].present? ? options[:formats] : [:pdf] )
|
11
|
-
send_data PdfGem::pdf_from_string(params), type: Mime[:pdf], disposition: (params[:disposition].present? ? params[:disposition] : 'inline'), :filename => options[:filename]
|
12
|
-
end
|
1
|
+
module PdfGem
|
2
|
+
|
3
|
+
class PdfGemRailtie < Rails::Railtie
|
4
|
+
initializer "my_railtie.configure_rails_initialization" do
|
13
5
|
|
14
|
-
|
15
|
-
|
6
|
+
ActionController::Renderers.add :pdf do |template, options|
|
7
|
+
params = options.except(:prefixes, :template, :disposition, :url, :html, :filename, :formats)
|
8
|
+
params[:html] = render_to_string(:action => (template.present? ? template : options.template), formats: options[:formats].present? ? options[:formats] : [:pdf] )
|
9
|
+
send_data PdfGem::pdf_from_string(params), type: Mime[:pdf], disposition: (params[:disposition].present? ? params[:disposition] : 'inline'), :filename => options[:filename]
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionController::Renderers.add :pdf2 do |template, options|
|
13
|
+
params = options.except(:prefixes, :template, :disposition, :url, :html, :filename, :formats)
|
14
|
+
params[:html] = render_to_string(:action => (template.present? ? template : options.template), formats: options[:formats].present? ? options[:formats] : [:pdf] )
|
15
|
+
send_data PdfGem::pdf_from_string(params), type: Mime[:pdf], disposition: (params[:disposition].present? ? params[:disposition] : 'inline'), :filename => options[:filename]
|
16
|
+
end
|
17
|
+
if Mime::Type.lookup_by_extension(:pdf).nil?
|
18
|
+
Mime::Type.register('application/pdf', :pdf)
|
19
|
+
end
|
20
|
+
end
|
16
21
|
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
|
17
27
|
end
|
data/lib/tmp/7d5de811543153dac4c2146cdd00647d71bced27665b7463437d2dc30ad6efb08bf5c4625768b483.pdf
ADDED
Binary file
|
data/lib/tmp/b3f46a28a790a1b1baa1a8e3ba73e23203f03207d612f861060604b7a6fa4bcb33d1f42058264233.pdf
ADDED
Binary file
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
2
|
+
|
3
|
+
<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
4
|
+
<title>Test HTML File</title>
|
5
|
+
|
6
|
+
</head>
|
7
|
+
<body>
|
8
|
+
|
9
|
+
<p>This is a simple HTML file.</p>
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
</body></html>
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pdf_gem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Blasina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,6 +53,9 @@ files:
|
|
53
53
|
- lib/pdf_gem/version.rb
|
54
54
|
- lib/pdf_generator.js
|
55
55
|
- lib/renderer.rb
|
56
|
+
- lib/tmp/7d5de811543153dac4c2146cdd00647d71bced27665b7463437d2dc30ad6efb08bf5c4625768b483.pdf
|
57
|
+
- lib/tmp/b3f46a28a790a1b1baa1a8e3ba73e23203f03207d612f861060604b7a6fa4bcb33d1f42058264233.pdf
|
58
|
+
- lib/tmp/yt2g01tvjh8p6qu2dpk950s443kckym9ke2s6opv.html
|
56
59
|
homepage: https://github.com/blasko03/pdf_gem
|
57
60
|
licenses:
|
58
61
|
- Apache-2.0
|