pdf_gem 1.0.8 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -10
- data/lib/pdf_gem.rb +1 -1
- data/lib/pdf_gem/version.rb +1 -1
- data/lib/pdf_generator.js +15 -3
- 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: 82f55cd6cf198ed27cc138949492e9c5ff5d6a5fc8303e846f8c6e424c5ed75e
|
4
|
+
data.tar.gz: c0245db08984bb5ceda9960a2543bea69c788c6c6669a0b78b7647a16d982984
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5857ff4e1b39e6b6624555fc3c1be761a88615a5a694690b73a95e9f37e76f642d051d7de227d56977d1a84b2eade4bb0cabba9ce70578eb54cff477a8d8b686
|
7
|
+
data.tar.gz: d614d15897d2b8eb795573fe6606fdc6aeef3aea0414267316d04b28bb2728187513f27acfb8f8b7db8918e6b4436ff1a8a54d898402fb2441379ddb4e57f451
|
data/README.md
CHANGED
@@ -25,15 +25,6 @@ Or install it yourself as:
|
|
25
25
|
$ gem install pdf_gem
|
26
26
|
```
|
27
27
|
|
28
|
-
Add this lines to `application.rb`
|
29
|
-
```ruby
|
30
|
-
ActionController::Renderers.add :pdf do |template, options|
|
31
|
-
PdfGem.renderer(template, options)
|
32
|
-
end
|
33
|
-
```
|
34
|
-
> **NOTE** You can change the :pdf in some other name if you have conflicts with other similar libraries
|
35
|
-
|
36
|
-
|
37
28
|
You may need to add
|
38
29
|
```ruby
|
39
30
|
Mime::Type.register "application/pdf", :pdf
|
@@ -78,8 +69,24 @@ PdfGem.pdf_from_string(options)
|
|
78
69
|
## Options
|
79
70
|
|
80
71
|
- `options` <[Object]> Options object which might have the following properties:
|
81
|
-
- `url` <[string]> (Used only for PdfGem.pdf_from_url) This is the url to render.
|
72
|
+
- `url` <[string]> (Used only for PdfGem.pdf_from_url) This is the url to render.
|
82
73
|
- `html` <[string]> (Used only for PdfGem.pdf_from_string) This is the html string to render.
|
74
|
+
- `timeout` <[number]> Maximum navigation time in ms, default is 3000 ms.
|
75
|
+
- `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:
|
76
|
+
- `load` - consider navigation to be finished when the `load` event is fired.
|
77
|
+
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
78
|
+
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
79
|
+
- `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
80
|
+
- `cookies` <[Array]> set cookie in browser session
|
81
|
+
- `name` <[string]> required
|
82
|
+
- `value` <[string]> required
|
83
|
+
- `url` <[string]>
|
84
|
+
- `domain` <[string]>
|
85
|
+
- `path` <[string]>
|
86
|
+
- `expires` <[number]> Unix time in seconds.
|
87
|
+
- `httpOnly` <[boolean]>
|
88
|
+
- `secure` <[boolean]>
|
89
|
+
- `sameSite` <["Strict"|"Lax"]>
|
83
90
|
- `disposition` <[string]> (Use only for controller render) Disposition string (inline/attachment).
|
84
91
|
- `formats` <[string]> (Use only for controller render) Force to load view of a particular format (pdf, html, xml).
|
85
92
|
- `filename` <[string]> (Use only for controller render) Filename of the file.
|
data/lib/pdf_gem.rb
CHANGED
@@ -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,24 @@ const path = require('path');
|
|
6
6
|
(async () => {
|
7
7
|
|
8
8
|
var stdinBuffer = fs.readFileSync(0);
|
9
|
-
|
10
|
-
|
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');
|
17
|
+
const browser = await puppeteer.launch({ headless: true,args: [ '--no-sandbox']});
|
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
|
-
|
21
|
+
if(params.cookies != null){
|
22
|
+
for(var i = 0; i<params.cookies.length; i++)
|
23
|
+
await page.setCookie(params.cookies[i])
|
24
|
+
}
|
25
|
+
|
26
|
+
await page.goto(params.url, {waitUntil: (params.waitUntil != null ? params.waitUntil : 'load'), timeout: (params.timeout == null ? 30000 : params.timeout)});
|
15
27
|
await page.pdf(params);
|
16
28
|
process.stdout.write(filename)
|
17
29
|
}
|
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.1.0
|
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-
|
11
|
+
date: 2020-03-06 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
|