gotenberg-ruby 1.0.6 → 1.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d5bca5c31fb41596a72235309e9ac5156d156290a8d8f961b626e49e41a896a
4
- data.tar.gz: 1d2562aaef002bafbafdc1f31da3341de73271b2cb09a95f9eede6f36b76c38d
3
+ metadata.gz: bf64c508e70367b7dadec2eee14b54218989131a240da2d927b5ba15ad6c4af6
4
+ data.tar.gz: a703924073bf1e819413e1e12e8b7e4e3176f9ad54ae28c47c5913cf6c9fd723
5
5
  SHA512:
6
- metadata.gz: 4fa4fa88a317bc10f35fc9f01bcae87b14501f3fc5aeca9e67a70d3c1e433c863cfdd61fc19af4797a0a6aa16b3438542450eed7ca9a7d685f78e275ec102884
7
- data.tar.gz: 88fe62bc6fbc1e8f2db20cd4a797bfca471c01e45feb6636299e427d35dd8b55cb6900677386dacb6c9c2e8221b4c628431063d7de0621ee8b36d0856036af89
6
+ metadata.gz: 1ab5c3057c04f1db12300e8de19878df41f9d9fd1414d68fd79ce6daba0fe106ce547a600fa64650ac98fc6e0e1d5100231c7ed11474072f3f439b0b5d7b01b2
7
+ data.tar.gz: e02a364aa9f05af5d624a5fe9926b8b12ef7d7f774dc4ae236a3833c3de3be9fb3d324d8e8f035bedb11446fbbe8fcec519a99cfcda69e09624ac2c81d34accc
data/README.md CHANGED
@@ -25,6 +25,7 @@ gem "gotenberg-ruby"
25
25
  * [LibreOffice](#libreOffice)
26
26
  * [PDF Engines](#pdf-engines)
27
27
  * [Webhook](#webhook)
28
+ * [Exiftools](#exiftools)
28
29
 
29
30
  ### Run Gotenberg
30
31
 
@@ -163,7 +164,7 @@ in the HTML DOM are on the root level.
163
164
  ```ruby
164
165
  document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
165
166
  doc.html index_html
166
- doc.assets ['/path/to/my.css', '/path/to/my.js']
167
+ doc.assets '/path/to/my.css', '/path/to/my.js', ['<binary string>', 'my.png']
167
168
  end
168
169
  ```
169
170
 
@@ -207,7 +208,15 @@ You may convert markdown files with:
207
208
 
208
209
  ```ruby
209
210
  document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
210
- doc.markdown wrapper_html, ['/path/to/file.md']
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']
211
220
  end
212
221
  ```
213
222
 
@@ -233,8 +242,8 @@ requirement is that their paths in the HTML DOM are on the root level.
233
242
 
234
243
  ```ruby
235
244
  document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
236
- doc.markdown wrapper_html, ['/path/to/file.md', '/path/to/my2.md']
237
- doc.assets ['/path/to/my.css', '/path/to/my.js']
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']
238
247
  end
239
248
  ```
240
249
 
@@ -483,7 +492,7 @@ If you send many documents, Gotenberg will return a ZIP archive with the PDFs:
483
492
 
484
493
  ```ruby
485
494
  document = Gotenberg::Libreoffice.call(ENV['GOTENBERG_URL']) do |doc|
486
- 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']
487
496
  end
488
497
 
489
498
  # will return binary data with zip archive content
@@ -497,7 +506,7 @@ You may also merge them into one unique PDF:
497
506
  ```ruby
498
507
  document = Gotenberg::Libreoffice.call(ENV['GOTENBERG_URL']) do |doc|
499
508
  doc.merge
500
- 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']
501
510
  end
502
511
  ```
503
512
 
@@ -564,7 +573,7 @@ Merging PDFs is as simple as:
564
573
 
565
574
  ```ruby
566
575
  document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
567
- 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']
568
577
  end
569
578
  ```
570
579
 
@@ -587,7 +596,7 @@ You may convert a PDF to a specific PDF format with:
587
596
 
588
597
  ```ruby
589
598
  document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
590
- doc.convert 'PDF/A-1a', '/path/to/my.pdf'
599
+ doc.convert '/path/to/my.pdf', format: 'PDF/A-1a'
591
600
  end
592
601
  ```
593
602
 
@@ -595,7 +604,7 @@ If you send many PDFs, Gotenberg will return a ZIP archive with the PDFs:
595
604
 
596
605
  ```ruby
597
606
  document = Gotenberg::PdfEngines.call(ENV['GOTENBERG_URL']) do |doc|
598
- doc.convert 'PDF/A-1a', '/path/to/my.pdf', '/path/to/my2.pdf', '/path/to/my3.pdf'
607
+ doc.convert '/path/to/my.pdf', '/path/to/my2.pdf', '/path/to/my3.pdf', ['<binary data>', 'some.pdf'], format: 'PDF/A-1a'
599
608
  end
600
609
 
601
610
  # will return binary data with zip archive content
@@ -640,3 +649,19 @@ document = Gotenberg::Chromium.call(ENV['GOTENBERG_URL']) do |doc|
640
649
  doc.webhook 'https://my.webhook.url', 'https://my.webhook.error.url'
641
650
  end
642
651
  ```
652
+
653
+ ### Exiftools
654
+
655
+ Gem also proxify (expert mode) access to mini_exiftools througth *Gotenberg::Exiftools* class.
656
+ You can change PDF metadata manually:
657
+
658
+ ```ruby
659
+ binary = Gotenberg::Exiftools.modify(pdf_binary, { title: 'Document 1' })
660
+
661
+ # save PDF file
662
+ File.open('filename.pdf', 'wb') do |file|
663
+ file << binary
664
+ end
665
+ ```
666
+
667
+ ⚠️ Class is just wrapper around *MiniExiftool* class, so you need handle exceptions manually/carefully in begin/rescue block.
@@ -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 Files
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
- binary_assets(compiler.assets)
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, markdowns = []
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
- # Sets the additional files, like images, fonts, stylesheets, and so on.
61
- def binary_assets sources
62
- sources.each do |(io, filename)|
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
@@ -1,7 +1,8 @@
1
1
  require 'gotenberg/chromium/properties'
2
- require 'gotenberg/chromium/files'
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
 
@@ -43,7 +46,6 @@ module Gotenberg
43
46
  response || raise(exception)
44
47
  end
45
48
 
46
-
47
49
  private
48
50
 
49
51
  def modify_metadata?
@@ -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 Files
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
- files << multipart_file(IO.binread(source), merge_prefix(index) + File.basename(source))
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/files'
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 Files
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
- files << multipart_file(IO.binread(source), merge_prefix(index) + File.basename(source))
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 format, *sources
27
- properties['pdfFormat'] = format
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/files'
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
@@ -1,3 +1,3 @@
1
1
  module Gotenberg
2
- VERSION = '1.0.6'
2
+ VERSION = '1.0.8'
3
3
  end
@@ -5,6 +5,7 @@ module Gotenberg
5
5
  autoload :Chromium, 'gotenberg/chromium'
6
6
  autoload :Libreoffice, 'gotenberg/libreoffice'
7
7
  autoload :PdfEngines, 'gotenberg/pdf_engines'
8
+ autoload :Exiftools, 'gotenberg/exiftools'
8
9
  autoload :Configuration, 'gotenberg/configuration'
9
10
 
10
11
  def self.configuration
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.6
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-09-28 00:00:00.000000000 Z
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