pdf_gem 1.0.11 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +12 -2
- data/lib/pdf_gem/version.rb +1 -1
- data/lib/pdf_gem.rb +1 -1
- data/lib/pdf_generator.js +7 -2
- metadata +3 -6
- data/lib/tmp/7d5de811543153dac4c2146cdd00647d71bced27665b7463437d2dc30ad6efb08bf5c4625768b483.pdf +0 -0
- data/lib/tmp/b3f46a28a790a1b1baa1a8e3ba73e23203f03207d612f861060604b7a6fa4bcb33d1f42058264233.pdf +0 -0
- data/lib/tmp/yt2g01tvjh8p6qu2dpk950s443kckym9ke2s6opv.html +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d54ca3662a3eec994cb6db848726b581322d9dc3d59049b463b09faa241dbca2
|
4
|
+
data.tar.gz: 6eb2168b46f4a6ac7ce9fe374159254250626e24868ea428d11e7836bea4c152
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7621b4253713b87a757d95a2f1c6a9b4a3b22c3f4b554a2a955e2ddc16e2acb21cb35e80b459bdaeed4b17dffac3b81404949a25c923d67a1eee8bbc2421039c
|
7
|
+
data.tar.gz: effa187152a74ba3e94a6362b600fdb1b793b2c2f0c0da3bc5809c470a4adca16d8cc1b818ef43bba9513adc0929b7d07e576a4a50283b6f203ca13235e73aec
|
data/README.md
CHANGED
@@ -69,14 +69,24 @@ PdfGem.pdf_from_string(options)
|
|
69
69
|
## Options
|
70
70
|
|
71
71
|
- `options` <[Object]> Options object which might have the following properties:
|
72
|
-
- `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.
|
73
|
+
- `html` <[string]> (Used only for PdfGem.pdf_from_string) This is the html string to render.
|
73
74
|
- `timeout` <[number]> Maximum navigation time in ms, default is 3000 ms.
|
74
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:
|
75
76
|
- `load` - consider navigation to be finished when the `load` event is fired.
|
76
77
|
- `domcontentloaded` - consider navigation to be finished when the `DOMContentLoaded` event is fired.
|
77
78
|
- `networkidle0` - consider navigation to be finished when there are no more than 0 network connections for at least `500` ms.
|
78
79
|
- `networkidle2` - consider navigation to be finished when there are no more than 2 network connections for at least `500` ms.
|
79
|
-
- `
|
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"]>
|
80
90
|
- `disposition` <[string]> (Use only for controller render) Disposition string (inline/attachment).
|
81
91
|
- `formats` <[string]> (Use only for controller render) Force to load view of a particular format (pdf, html, xml).
|
82
92
|
- `filename` <[string]> (Use only for controller render) Filename of the file.
|
data/lib/pdf_gem/version.rb
CHANGED
data/lib/pdf_gem.rb
CHANGED
@@ -20,7 +20,7 @@ module PdfGem
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.pdf_from_string(params)
|
23
|
-
tmp = File.join(
|
23
|
+
tmp = File.join('/', 'tmp')
|
24
24
|
Dir.mkdir(tmp) unless File.exist?(tmp)
|
25
25
|
html_file = File.join(tmp, "#{rand(36**40).to_s(36)}.html")
|
26
26
|
File.open(html_file, "w+") do |f|
|
data/lib/pdf_generator.js
CHANGED
@@ -7,17 +7,22 @@ const path = require('path');
|
|
7
7
|
|
8
8
|
var stdinBuffer = fs.readFileSync(0);
|
9
9
|
|
10
|
-
var tmp = path.join(
|
10
|
+
var tmp = path.join('/', 'tmp');
|
11
11
|
|
12
12
|
if (!fs.existsSync(tmp)){
|
13
13
|
fs.mkdirSync(tmp);
|
14
14
|
}
|
15
15
|
|
16
16
|
const filename = path.join(tmp, crypto.randomBytes(40).toString('hex')+ '.pdf');
|
17
|
-
const browser = await puppeteer.launch();
|
17
|
+
const browser = await puppeteer.launch({ headless: true,args: [ '--no-sandbox']});
|
18
18
|
try{
|
19
19
|
const params = {...JSON.parse(Buffer.from(stdinBuffer.toString(), 'base64').toString('utf-8')), ...{path: filename}};
|
20
20
|
const page = await browser.newPage();
|
21
|
+
if(params.cookies != null){
|
22
|
+
for(var i = 0; i<params.cookies.length; i++)
|
23
|
+
await page.setCookie(params.cookies[i])
|
24
|
+
}
|
25
|
+
|
21
26
|
await page.goto(params.url, {waitUntil: (params.waitUntil != null ? params.waitUntil : 'load'), timeout: (params.timeout == null ? 30000 : params.timeout)});
|
22
27
|
await page.pdf(params);
|
23
28
|
process.stdout.write(filename)
|
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.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Blasina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,9 +53,6 @@ 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
|
59
56
|
homepage: https://github.com/blasko03/pdf_gem
|
60
57
|
licenses:
|
61
58
|
- Apache-2.0
|
@@ -76,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
76
73
|
- !ruby/object:Gem::Version
|
77
74
|
version: '0'
|
78
75
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
76
|
+
rubygems_version: 3.2.16
|
80
77
|
signing_key:
|
81
78
|
specification_version: 4
|
82
79
|
summary: Gem for creating pdf from html
|
data/lib/tmp/7d5de811543153dac4c2146cdd00647d71bced27665b7463437d2dc30ad6efb08bf5c4625768b483.pdf
DELETED
Binary file
|
data/lib/tmp/b3f46a28a790a1b1baa1a8e3ba73e23203f03207d612f861060604b7a6fa4bcb33d1f42058264233.pdf
DELETED
Binary file
|
@@ -1,13 +0,0 @@
|
|
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>
|