gotenberg-ruby 1.0.7 → 1.0.8
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 -9
- data/lib/gotenberg/chromium/{files.rb → tools.rb} +7 -31
- data/lib/gotenberg/chromium.rb +5 -2
- data/lib/gotenberg/files.rb +29 -0
- data/lib/gotenberg/libreoffice/{files.rb → tools.rb} +4 -12
- data/lib/gotenberg/libreoffice.rb +3 -2
- data/lib/gotenberg/pdf_engines/{files.rb → tools.rb} +9 -17
- data/lib/gotenberg/pdf_engines.rb +3 -2
- data/lib/gotenberg/version.rb +1 -1
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf64c508e70367b7dadec2eee14b54218989131a240da2d927b5ba15ad6c4af6
|
4
|
+
data.tar.gz: a703924073bf1e819413e1e12e8b7e4e3176f9ad54ae28c47c5913cf6c9fd723
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ab5c3057c04f1db12300e8de19878df41f9d9fd1414d68fd79ce6daba0fe106ce547a600fa64650ac98fc6e0e1d5100231c7ed11474072f3f439b0b5d7b01b2
|
7
|
+
data.tar.gz: e02a364aa9f05af5d624a5fe9926b8b12ef7d7f774dc4ae236a3833c3de3be9fb3d324d8e8f035bedb11446fbbe8fcec519a99cfcda69e09624ac2c81d34accc
|
data/README.md
CHANGED
@@ -164,7 +164,7 @@ in the HTML DOM are on the root level.
|
|
164
164
|
```ruby
|
165
165
|
document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
|
166
166
|
doc.html index_html
|
167
|
-
doc.assets
|
167
|
+
doc.assets '/path/to/my.css', '/path/to/my.js', ['<binary string>', 'my.png']
|
168
168
|
end
|
169
169
|
```
|
170
170
|
|
@@ -208,7 +208,15 @@ You may convert markdown files with:
|
|
208
208
|
|
209
209
|
```ruby
|
210
210
|
document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
|
211
|
-
doc.markdown wrapper_html,
|
211
|
+
doc.markdown wrapper_html, '/path/to/file.md'
|
212
|
+
end
|
213
|
+
```
|
214
|
+
|
215
|
+
Or with raw input:
|
216
|
+
|
217
|
+
```ruby
|
218
|
+
document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
|
219
|
+
doc.markdown wrapper_html, ['<binary data>', 'file.md']
|
212
220
|
end
|
213
221
|
```
|
214
222
|
|
@@ -234,8 +242,8 @@ requirement is that their paths in the HTML DOM are on the root level.
|
|
234
242
|
|
235
243
|
```ruby
|
236
244
|
document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
|
237
|
-
doc.markdown wrapper_html,
|
238
|
-
doc.assets
|
245
|
+
doc.markdown wrapper_html, '/path/to/file.md'
|
246
|
+
doc.assets '/path/to/my.css', '/path/to/my.js', '/path/to/my2.md', ['<binary data>', 'file_2.md']
|
239
247
|
end
|
240
248
|
```
|
241
249
|
|
@@ -484,7 +492,7 @@ If you send many documents, Gotenberg will return a ZIP archive with the PDFs:
|
|
484
492
|
|
485
493
|
```ruby
|
486
494
|
document = Gotenberg::Libreoffice.call(ENV['GOTENBERG_URL']) do |doc|
|
487
|
-
doc.convert '/path/to/my.docx', '/path/to/my.xlsx'
|
495
|
+
doc.convert '/path/to/my.docx', '/path/to/my.xlsx', ['<binary data>', 'some.odt']
|
488
496
|
end
|
489
497
|
|
490
498
|
# will return binary data with zip archive content
|
@@ -498,7 +506,7 @@ You may also merge them into one unique PDF:
|
|
498
506
|
```ruby
|
499
507
|
document = Gotenberg::Libreoffice.call(ENV['GOTENBERG_URL']) do |doc|
|
500
508
|
doc.merge
|
501
|
-
doc.convert '/path/to/my.docx', '/path/to/my.xlsx'
|
509
|
+
doc.convert '/path/to/my.docx', '/path/to/my.xlsx', ['<binary data>', 'some.odt']
|
502
510
|
end
|
503
511
|
```
|
504
512
|
|
@@ -565,7 +573,7 @@ Merging PDFs is as simple as:
|
|
565
573
|
|
566
574
|
```ruby
|
567
575
|
document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
|
568
|
-
doc.merge '/path/to/my.pdf', '/path/to/my2.pdf'
|
576
|
+
doc.merge '/path/to/my.pdf', '/path/to/my2.pdf', ['<binary data>', 'some.pdf']
|
569
577
|
end
|
570
578
|
```
|
571
579
|
|
@@ -588,7 +596,7 @@ You may convert a PDF to a specific PDF format with:
|
|
588
596
|
|
589
597
|
```ruby
|
590
598
|
document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
|
591
|
-
doc.convert '
|
599
|
+
doc.convert '/path/to/my.pdf', format: 'PDF/A-1a'
|
592
600
|
end
|
593
601
|
```
|
594
602
|
|
@@ -596,7 +604,7 @@ If you send many PDFs, Gotenberg will return a ZIP archive with the PDFs:
|
|
596
604
|
|
597
605
|
```ruby
|
598
606
|
document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
|
599
|
-
doc.convert '
|
607
|
+
doc.convert '/path/to/my.pdf', '/path/to/my2.pdf', '/path/to/my3.pdf', ['<binary data>', 'some.pdf'], format: 'PDF/A-1a'
|
600
608
|
end
|
601
609
|
|
602
610
|
# will return binary data with zip archive content
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday/multipart'
|
3
1
|
require 'gotenberg/compiler'
|
4
2
|
|
5
3
|
module Gotenberg
|
6
4
|
class Chromium
|
7
|
-
module
|
5
|
+
module Tools
|
8
6
|
# Adds a header to each page.
|
9
7
|
# Note: it automatically sets the filename to "header.html", as required by Gotenberg.
|
10
8
|
def header header
|
@@ -35,7 +33,7 @@ module Gotenberg
|
|
35
33
|
|
36
34
|
files << multipart_file(compiler.body, 'index.html', 'text/html')
|
37
35
|
|
38
|
-
|
36
|
+
assets *compiler.assets
|
39
37
|
|
40
38
|
@endpoint = '/forms/chromium/convert/html'
|
41
39
|
|
@@ -45,44 +43,22 @@ module Gotenberg
|
|
45
43
|
# Converts one or more markdown files to PDF.
|
46
44
|
# Note: it automatically sets the index filename to "index.html", as required by Gotenberg.
|
47
45
|
# See https://gotenberg.dev/docs/modules/chromium#markdown.
|
48
|
-
def markdown index,
|
46
|
+
def markdown index, markdown
|
49
47
|
files << multipart_file(index, 'index.html', 'text/html')
|
48
|
+
files << multipart_file(*load_file_from_source(markdown), 'text/markdown')
|
50
49
|
|
51
|
-
markdowns.each do |f|
|
52
|
-
files << multipart_file(IO.binread(f), File.basename(f), 'text/markdown')
|
53
|
-
end
|
54
|
-
|
55
50
|
@endpoint = '/forms/chromium/convert/markdown'
|
56
51
|
|
57
52
|
self
|
58
53
|
end
|
59
54
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
files << multipart_file(io, filename)
|
64
|
-
end
|
65
|
-
|
66
|
-
self
|
67
|
-
end
|
68
|
-
|
69
|
-
def assets sources
|
70
|
-
sources.each do |f|
|
71
|
-
files << multipart_file(IO.binread(f), File.basename(f))
|
55
|
+
def assets *sources
|
56
|
+
sources.each do |source|
|
57
|
+
files << multipart_file(*load_file_from_source(source))
|
72
58
|
end
|
73
59
|
|
74
60
|
self
|
75
61
|
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
def files
|
80
|
-
@files ||= []
|
81
|
-
end
|
82
|
-
|
83
|
-
def multipart_file body, filename, content_type = 'application/octet-stream'
|
84
|
-
Faraday::Multipart::FilePart.new(StringIO.new(body), content_type, filename)
|
85
|
-
end
|
86
62
|
end
|
87
63
|
end
|
88
64
|
end
|
data/lib/gotenberg/chromium.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
require 'gotenberg/chromium/properties'
|
2
|
-
require 'gotenberg/chromium/
|
2
|
+
require 'gotenberg/chromium/tools'
|
3
3
|
require 'gotenberg/headers'
|
4
4
|
require 'gotenberg/metadata'
|
5
|
+
require 'gotenberg/files'
|
5
6
|
require 'gotenberg/client'
|
6
7
|
require 'gotenberg/exiftools'
|
7
8
|
require 'gotenberg/extractors'
|
@@ -10,7 +11,7 @@ require 'gotenberg/backtrace'
|
|
10
11
|
|
11
12
|
module Gotenberg
|
12
13
|
class Chromium
|
13
|
-
include Properties, Files, Headers, Metadata, Extractors
|
14
|
+
include Properties, Files, Headers, Metadata, Tools, Extractors
|
14
15
|
|
15
16
|
attr_accessor :base_path
|
16
17
|
attr_reader :endpoint, :response, :exception
|
@@ -32,6 +33,8 @@ module Gotenberg
|
|
32
33
|
transform
|
33
34
|
modify_metadata if modify_metadata?
|
34
35
|
|
36
|
+
puts files.inspect
|
37
|
+
|
35
38
|
self
|
36
39
|
end
|
37
40
|
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'faraday/multipart'
|
3
|
+
|
4
|
+
module Gotenberg
|
5
|
+
module Files
|
6
|
+
|
7
|
+
private
|
8
|
+
|
9
|
+
def files
|
10
|
+
@files ||= []
|
11
|
+
end
|
12
|
+
|
13
|
+
def load_file_from_source source
|
14
|
+
io, filename =
|
15
|
+
case source
|
16
|
+
when String
|
17
|
+
[IO.binread(source), File.basename(source)]
|
18
|
+
when Array
|
19
|
+
source
|
20
|
+
end
|
21
|
+
|
22
|
+
[io, filename]
|
23
|
+
end
|
24
|
+
|
25
|
+
def multipart_file body, filename, content_type = 'application/octet-stream'
|
26
|
+
Faraday::Multipart::FilePart.new(StringIO.new(body), content_type, filename)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -1,10 +1,8 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday/multipart'
|
3
1
|
require 'gotenberg/utilities/index'
|
4
2
|
|
5
3
|
module Gotenberg
|
6
4
|
class Libreoffice
|
7
|
-
module
|
5
|
+
module Tools
|
8
6
|
|
9
7
|
# Converts the given document(s) to PDF(s).
|
10
8
|
# Gotenberg will return either a unique PDF if you request a merge or a ZIP archive with the PDFs.
|
@@ -12,7 +10,9 @@ module Gotenberg
|
|
12
10
|
# See https://gotenberg.dev/docs/modules/libreoffice#route.
|
13
11
|
def convert *sources
|
14
12
|
sources.each.with_index(1) do |source, index|
|
15
|
-
|
13
|
+
io, filename = load_file_from_source(source)
|
14
|
+
|
15
|
+
files << multipart_file(io, merge_prefix(index) + filename)
|
16
16
|
end
|
17
17
|
|
18
18
|
@endpoint = '/forms/libreoffice/convert'
|
@@ -22,10 +22,6 @@ module Gotenberg
|
|
22
22
|
|
23
23
|
private
|
24
24
|
|
25
|
-
def files
|
26
|
-
@files ||= []
|
27
|
-
end
|
28
|
-
|
29
25
|
def zip_mode?
|
30
26
|
properties['merge'] != true && files.size > 1
|
31
27
|
end
|
@@ -33,10 +29,6 @@ module Gotenberg
|
|
33
29
|
def merge_prefix number
|
34
30
|
properties['merge'] ? Gotenberg::Utilities::Index::to_alpha(number) + '_' : ''
|
35
31
|
end
|
36
|
-
|
37
|
-
def multipart_file body, filename, content_type = 'application/octet-stream'
|
38
|
-
Faraday::Multipart::FilePart.new(StringIO.new(body), content_type, filename)
|
39
|
-
end
|
40
32
|
end
|
41
33
|
end
|
42
34
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'gotenberg/libreoffice/properties'
|
2
|
-
require 'gotenberg/libreoffice/
|
2
|
+
require 'gotenberg/libreoffice/tools'
|
3
3
|
require 'gotenberg/headers'
|
4
4
|
require 'gotenberg/metadata'
|
5
|
+
require 'gotenberg/files'
|
5
6
|
require 'gotenberg/client'
|
6
7
|
require 'gotenberg/exiftools'
|
7
8
|
require 'gotenberg/exceptions'
|
8
9
|
|
9
10
|
module Gotenberg
|
10
11
|
class Libreoffice
|
11
|
-
include Properties, Files, Headers, Metadata
|
12
|
+
include Properties, Files, Headers, Metadata, Tools
|
12
13
|
|
13
14
|
attr_accessor :base_path
|
14
15
|
attr_reader :endpoint, :response, :exception
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
require 'faraday/multipart'
|
3
1
|
require 'gotenberg/utilities/index'
|
4
2
|
|
5
3
|
module Gotenberg
|
6
4
|
class PdfEngines
|
7
|
-
module
|
5
|
+
module Tools
|
8
6
|
|
9
7
|
# Merges PDFs into a unique PDF.
|
10
8
|
# Note: the merging order is determined by the order of the arguments.
|
11
9
|
# See https://gotenberg.dev/docs/modules/pdf-engines#merge.
|
12
10
|
def merge *sources
|
13
11
|
sources.each.with_index(1) do |source, index|
|
14
|
-
|
12
|
+
io, filename = load_file_from_source(source)
|
13
|
+
|
14
|
+
files << multipart_file(io, merge_prefix(index) + filename)
|
15
15
|
end
|
16
16
|
|
17
17
|
@endpoint = '/forms/pdfengines/merge'
|
@@ -23,13 +23,13 @@ module Gotenberg
|
|
23
23
|
# Gotenberg will return the PDF or a ZIP archive with the PDFs.
|
24
24
|
# https://gotenberg.dev/docs/modules/pdf-engines#convert.
|
25
25
|
# https://gotenberg.dev/docs/modules/pdf-engines#engines.
|
26
|
-
def convert
|
27
|
-
|
28
|
-
|
29
|
-
sources.each.with_index(1) do |source, index|
|
30
|
-
files << multipart_file(IO.binread(source), File.basename(source))
|
26
|
+
def convert *sources, format: 'PDF/A-1a'
|
27
|
+
sources.each do |source|
|
28
|
+
files << multipart_file(*load_file_from_source(source))
|
31
29
|
end
|
32
30
|
|
31
|
+
properties['pdfFormat'] = format
|
32
|
+
|
33
33
|
@endpoint = '/forms/pdfengines/convert'
|
34
34
|
@pdf_engines_convert = true
|
35
35
|
|
@@ -38,10 +38,6 @@ module Gotenberg
|
|
38
38
|
|
39
39
|
private
|
40
40
|
|
41
|
-
def files
|
42
|
-
@files ||= []
|
43
|
-
end
|
44
|
-
|
45
41
|
def zip_mode?
|
46
42
|
@pdf_engines_convert && files.size > 1
|
47
43
|
end
|
@@ -49,10 +45,6 @@ module Gotenberg
|
|
49
45
|
def merge_prefix number
|
50
46
|
Gotenberg::Utilities::Index::to_alpha(number) + '_'
|
51
47
|
end
|
52
|
-
|
53
|
-
def multipart_file body, filename, content_type = 'application/octet-stream'
|
54
|
-
Faraday::Multipart::FilePart.new(StringIO.new(body), content_type, filename)
|
55
|
-
end
|
56
48
|
end
|
57
49
|
end
|
58
50
|
end
|
@@ -1,14 +1,15 @@
|
|
1
1
|
require 'gotenberg/pdf_engines/properties'
|
2
|
-
require 'gotenberg/pdf_engines/
|
2
|
+
require 'gotenberg/pdf_engines/tools'
|
3
3
|
require 'gotenberg/headers'
|
4
4
|
require 'gotenberg/metadata'
|
5
|
+
require 'gotenberg/files'
|
5
6
|
require 'gotenberg/client'
|
6
7
|
require 'gotenberg/exiftools'
|
7
8
|
require 'gotenberg/exceptions'
|
8
9
|
|
9
10
|
module Gotenberg
|
10
11
|
class PdfEngines
|
11
|
-
include Properties, Files, Headers, Metadata
|
12
|
+
include Properties, Files, Headers, Metadata, Tools
|
12
13
|
|
13
14
|
attr_accessor :base_path
|
14
15
|
attr_reader :endpoint, :response, :exception
|
data/lib/gotenberg/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gotenberg-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sanzstez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-10-
|
11
|
+
date: 2022-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -90,23 +90,24 @@ files:
|
|
90
90
|
- lib/gotenberg/analyzers/resource.rb
|
91
91
|
- lib/gotenberg/backtrace.rb
|
92
92
|
- lib/gotenberg/chromium.rb
|
93
|
-
- lib/gotenberg/chromium/files.rb
|
94
93
|
- lib/gotenberg/chromium/properties.rb
|
94
|
+
- lib/gotenberg/chromium/tools.rb
|
95
95
|
- lib/gotenberg/client.rb
|
96
96
|
- lib/gotenberg/compiler.rb
|
97
97
|
- lib/gotenberg/configuration.rb
|
98
98
|
- lib/gotenberg/exceptions.rb
|
99
99
|
- lib/gotenberg/exiftools.rb
|
100
100
|
- lib/gotenberg/extractors.rb
|
101
|
+
- lib/gotenberg/files.rb
|
101
102
|
- lib/gotenberg/headers.rb
|
102
103
|
- lib/gotenberg/helpers/action_view.rb
|
103
104
|
- lib/gotenberg/libreoffice.rb
|
104
|
-
- lib/gotenberg/libreoffice/files.rb
|
105
105
|
- lib/gotenberg/libreoffice/properties.rb
|
106
|
+
- lib/gotenberg/libreoffice/tools.rb
|
106
107
|
- lib/gotenberg/metadata.rb
|
107
108
|
- lib/gotenberg/pdf_engines.rb
|
108
|
-
- lib/gotenberg/pdf_engines/files.rb
|
109
109
|
- lib/gotenberg/pdf_engines/properties.rb
|
110
|
+
- lib/gotenberg/pdf_engines/tools.rb
|
110
111
|
- lib/gotenberg/railtie.rb
|
111
112
|
- lib/gotenberg/utilities/index.rb
|
112
113
|
- lib/gotenberg/utilities/inline_resource.rb
|