libis-format 2.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f563ad694fd3d0c9e4a9f0da3309c99ac4b103e6027fcc9cda1606f0f67549c2
4
- data.tar.gz: 5cee3f4b3bb1e51db492ee14bf919b0ce0fa69e267292380364c32b4eec40b4e
3
+ metadata.gz: bfe52fc3216a0da8528941b4232c252880006137cc92fe8d42512840f5b7ab7d
4
+ data.tar.gz: 349303abd8b4d8748960713933f532bae3ca83d45613a79321269497baa6ae2a
5
5
  SHA512:
6
- metadata.gz: 409ea1fac8f8be4d2519f189090207b6a550a1b1ce174a71fa1886c69b667001459d4bdccd850dd55373199ae5553ebd02183e15eebc88a73d0ac3f8093f7d12
7
- data.tar.gz: d3e4d77ddcaab1f5050aaf4acb02e74a221566abedb94062254efbc24d18703c8fdd739644b1cd5435b54a4497e77c82bdcbcb218d121bfaf135e483662aca06
6
+ metadata.gz: '0917e66b03e3bf008dd3a86761f9004d93d1fbc3c02c8c692a1f6f312f25c4edc0a1536b73e4a01043b4e03c85125437ae1307c49349bdee7c46d3f5b2503231'
7
+ data.tar.gz: 29bd68dce1a8f5f2c0216299b29268d3fdcbafaed4282b7076fac4810762fb377a403dbc08dc23672a3eda4bb17cae8c8882bb24d21980396d3c2943935d1437
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ mkmf.log
18
18
  *.pyc
19
19
  tools/pdf/
20
20
  /test*
21
+ /*~
22
+ /*.pdf
data/lib/libis/format.rb CHANGED
@@ -18,4 +18,10 @@ module Libis
18
18
  TOOL_DIR = File.join(ROOT_DIR, 'tools')
19
19
 
20
20
  end
21
- end
21
+ end
22
+
23
+ class Object
24
+ def blank?
25
+ respond_to?(:empty?) ? !!empty? : !self
26
+ end unless defined? :blank?
27
+ end
@@ -36,6 +36,7 @@ module Libis
36
36
  fop: 5 * 60,
37
37
  identification_tool: 5 * 60,
38
38
  office_to_pdf: 5 * 60,
39
+ pdf_select: 5 * 60,
39
40
  pdf_copy: 5 * 60,
40
41
  pdf_merge: 5 * 60,
41
42
  pdf_optimizer: 5 * 60,
@@ -4,6 +4,7 @@
4
4
  require 'tmpdir'
5
5
  require 'libis/tools/logger'
6
6
  require 'libis/tools/temp_file'
7
+ require 'libis/tools/extend/string'
7
8
  require 'libis/format/library'
8
9
 
9
10
  require_relative 'repository'
@@ -33,6 +33,10 @@ module Libis
33
33
  [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include?(format)
34
34
  end
35
35
 
36
+ def self.category
37
+ :splitter
38
+ end
39
+
36
40
  def image_split(_)
37
41
  #force usage of this converter
38
42
  end
@@ -2,10 +2,7 @@
2
2
 
3
3
  require_relative 'base'
4
4
 
5
- require 'libis/tools/extend/hash'
6
- require 'libis/format/tool/pdf_copy'
7
- require 'libis/format/tool/pdf_to_pdfa'
8
- require 'libis/format/tool/pdf_optimizer'
5
+ require 'libis/format/tool/pdf_metadata'
9
6
 
10
7
  module Libis
11
8
  module Format
@@ -20,84 +17,19 @@ module Libis
20
17
 
21
18
  def self.output_types(format = nil)
22
19
  return [] unless input_types.include?(format) if format
23
- [:PDF, :PDFA]
24
- end
25
-
26
- def title(v)
27
- @options[:title] = v.blank? ? nil : v
28
- end
29
-
30
- def author(v)
31
- @options[:author] = v.blank? ? nil : v
32
- end
33
-
34
- def creator(v)
35
- @options[:creator] = v.blank? ? nil : v
36
- end
37
-
38
- def keywords(v)
39
- @options[:keywords] = v.blank? ? nil : v
40
- end
41
-
42
- def subject(v)
43
- @options[:subject] = v.blank? ? nil : v
44
- end
45
-
46
- # Select a partial list of pages
47
- # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
48
- def range(selection)
49
- @options[:ranges] = selection.blank? ? nil : selection
20
+ [:PDFA]
50
21
  end
51
22
 
52
23
  def convert(source, target, format, opts = {})
53
24
  super
54
25
 
55
- result = nil
56
-
57
- unless @options.empty?
58
- result = convert_pdf(source, target)
59
- return nil unless result
60
- source = result
61
- end
62
-
63
- if format == :PDFA and source
64
- result = pdf_to_pdfa(source, target)
65
- end
26
+ result = pdf_to_pdfa(source, target)
27
+ return nil unless result
66
28
 
67
29
  result
68
30
 
69
31
  end
70
32
 
71
- OPTIONS_TABLE = {
72
- title: 'md_title',
73
- author: 'md_author',
74
- creator: 'md_creator',
75
- keywords: 'md_keywords',
76
- subject: 'md_subject'
77
- }
78
-
79
- def convert_pdf(source, target)
80
-
81
- using_temp(target) do |tmpname|
82
- result = Libis::Format::Tool::PdfCopy.run(
83
- source, tmpname,
84
- @options.map {|k, v|
85
- if v.nil?
86
- nil
87
- else
88
- k = OPTIONS_TABLE[k] || k
89
- ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
90
- end}.compact.flatten
91
- )
92
- unless result[:err].empty?
93
- error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
94
- next nil
95
- end
96
- tmpname
97
- end
98
-
99
- end
100
-
101
33
  def pdf_to_pdfa(source, target)
102
34
 
103
35
  using_temp(target) do |tmpname|
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_metadata'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfMetadata < Libis::Format::Converter::Base
13
+
14
+ def self.input_types
15
+ [:PDF]
16
+ end
17
+
18
+ def self.output_types(format = nil)
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDF]
21
+ end
22
+
23
+ def title(v)
24
+ @options[:title] = v.blank? ? nil : v
25
+ end
26
+
27
+ def author(v)
28
+ @options[:author] = v.blank? ? nil : v
29
+ end
30
+
31
+ def creator(v)
32
+ @options[:creator] = v.blank? ? nil : v
33
+ end
34
+
35
+ def keywords(v)
36
+ @options[:keywords] = v.blank? ? nil : v
37
+ end
38
+
39
+ def subject(v)
40
+ @options[:subject] = v.blank? ? nil : v
41
+ end
42
+
43
+ def convert(source, target, format, opts = {})
44
+ super
45
+
46
+ result = nil
47
+
48
+ unless @options.empty?
49
+ result = convert_pdf(source, target)
50
+ return nil unless result
51
+ end
52
+
53
+ result
54
+
55
+ end
56
+
57
+ def convert_pdf(source, target)
58
+
59
+ using_temp(target) do |tmpname|
60
+ result = Libis::Format::Tool::PdfMetadata.run(
61
+ source, tmpname,
62
+ @options.map {|k, v|
63
+ if v.nil?
64
+ nil
65
+ else
66
+ ["--#{k}", v]
67
+ end}.compact.flatten
68
+ )
69
+ unless result[:err].empty?
70
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
71
+ next nil
72
+ end
73
+ tmpname
74
+ end
75
+
76
+ end
77
+
78
+ end
79
+
80
+ end
81
+ end
82
+ end
@@ -2,9 +2,6 @@
2
2
 
3
3
  require_relative 'base'
4
4
 
5
- require 'libis/tools/extend/hash'
6
- require 'libis/format/tool/pdf_copy'
7
- require 'libis/format/tool/pdf_to_pdfa'
8
5
  require 'libis/format/tool/pdf_optimizer'
9
6
 
10
7
  module Libis
@@ -0,0 +1,147 @@
1
+ # encoding: utf-8
2
+ require 'securerandom'
3
+
4
+ require_relative 'base'
5
+ require 'libis/format/tool/pdf_protect'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ RANDOM_CHARS = [('a'..'z'), ('A'..'Z'), ('0'..'9')].map(&:to_a).flatten
12
+
13
+ # noinspection DuplicatedCode
14
+ class PdfProtecter < Libis::Format::Converter::Base
15
+
16
+ def self.input_types
17
+ [:PDF]
18
+ end
19
+
20
+ def self.output_types(format = nil)
21
+ return [] unless input_types.include?(format) if format
22
+ [:PDF, :PDFA]
23
+ end
24
+
25
+ def pdf_protect(_)
26
+ #force usage of this converter
27
+ end
28
+
29
+ def initialize
30
+ super
31
+ @options[:edit_password] = SecureRandom.urlsafe_base64(31)
32
+ end
33
+
34
+ def edit_password(pwd)
35
+ @options[:edit_password] = pwd
36
+ end
37
+
38
+ def open_password(pwd)
39
+ @options[:open_password] = pwd
40
+ end
41
+
42
+ def assist(v)
43
+ @flags[:assist] = !!v
44
+ end
45
+
46
+ def copy(v)
47
+ @flags[:copy] = !!v
48
+ end
49
+
50
+ def print(v)
51
+ @flags[:print] = !!v
52
+ end
53
+
54
+ def comments(v)
55
+ @flags[:comments] = !!v
56
+ end
57
+
58
+ def fillin(v)
59
+ @flags[:fillin] = !!v
60
+ end
61
+
62
+ def manage(v)
63
+ @flags[:manage] = !!v
64
+ end
65
+
66
+ def edit(v)
67
+ @flags[:edit] = !!v
68
+ end
69
+
70
+ def convert(source, target, format, opts = {})
71
+ super
72
+
73
+ result = nil
74
+
75
+ unless @options.empty?
76
+ result = convert_pdf(source, target)
77
+ return nil unless result
78
+ source = result
79
+ end
80
+
81
+ if format == :PDFA and source
82
+ result = pdf_to_pdfa(source, target)
83
+ end
84
+
85
+ result
86
+
87
+ end
88
+
89
+ OPTIONS_TABLE = {
90
+ edit_password: 'edit-password',
91
+ open_password: 'open-password',
92
+ fillin: 'fill-in',
93
+ }
94
+
95
+ def convert_pdf(source, target)
96
+
97
+ using_temp(target) do |tmpname|
98
+ result = Libis::Format::Tool::PdfProtect.run(
99
+ source, tmpname,
100
+ [
101
+ @options.map { |k, v|
102
+ if v.nil?
103
+ nil
104
+ else
105
+ k = OPTIONS_TABLE[k] || k
106
+ ["--#{k}", v]
107
+ end
108
+ },
109
+ @flags.map { |k, v|
110
+ if !v
111
+ nil
112
+ else
113
+ k = OPTIONS_TABLE[k] || k
114
+ "--#{k}"
115
+ end
116
+ }
117
+ ].compact.flatten
118
+ )
119
+ unless result[:err].empty?
120
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
121
+ next nil
122
+ end
123
+ tmpname
124
+ end
125
+
126
+ end
127
+
128
+ def pdf_to_pdfa(source, target)
129
+
130
+ using_temp(target) do |tmpname|
131
+ result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
132
+ if result[:status] != 0
133
+ error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
134
+ next nil
135
+ else
136
+ warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
137
+ end
138
+ tmpname
139
+ end
140
+
141
+ end
142
+
143
+ end
144
+
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,77 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_select'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ # noinspection DuplicatedCode
12
+ class PdfSelecter < Libis::Format::Converter::Base
13
+
14
+ def self.input_types
15
+ [:PDF]
16
+ end
17
+
18
+ def self.output_types(format = nil)
19
+ return [] unless input_types.include?(format) if format
20
+ [:PDF]
21
+ end
22
+
23
+ def pdf_select(_)
24
+ #force usage of this converter
25
+ end
26
+
27
+ def initialize
28
+ super
29
+ @options[:range] = []
30
+ end
31
+
32
+ # Select a partial list of pages
33
+ # @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
34
+ def range(selection)
35
+ @options[:range] << selection unless selection.blank?
36
+ end
37
+
38
+ def convert(source, target, format, opts = {})
39
+ super
40
+
41
+ result = nil
42
+
43
+ unless @options.empty?
44
+ result = convert_pdf(source, target)
45
+ return nil unless result
46
+ end
47
+
48
+ result
49
+
50
+ end
51
+
52
+ def convert_pdf(source, target)
53
+
54
+ using_temp(target) do |tmpname|
55
+ result = Libis::Format::Tool::PdfSelect.run(
56
+ source, tmpname,
57
+ @options.map { |k, v|
58
+ if v.nil?
59
+ nil
60
+ else
61
+ ["--#{k}", v]
62
+ end }.compact.flatten
63
+ )
64
+ unless result[:err].empty?
65
+ error("Pdf selection encountered errors:\n%s", result[:err].join(join("\n")))
66
+ next nil
67
+ end
68
+ tmpname
69
+ end
70
+
71
+ end
72
+
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -17,20 +17,20 @@ module Libis
17
17
 
18
18
  def self.output_types(format = nil)
19
19
  return [] unless input_types.include?(format) if format
20
- [:PDF]
21
- end
22
-
23
- def pdf_split(_)
24
- #force usage of this converter
20
+ [:PDFA]
25
21
  end
26
22
 
27
23
  def self.category
28
24
  :splitter
29
25
  end
30
26
 
31
- # Split at given page. If omitted or nil, the source PDF will be split at every page
27
+ def initialize
28
+ super
29
+ end
30
+
31
+ # Split at given page. If omitted, nil or 0, the source PDF will be split at every page
32
32
  def page(v)
33
- @page = v unless v.blank
33
+ @options[:page] = v unless v.blank?
34
34
  end
35
35
 
36
36
  def convert(source, target, format, opts = {})
@@ -46,15 +46,20 @@ module Libis
46
46
 
47
47
  def split(source, target)
48
48
 
49
- options = @page ? ['--page', @page] : ['--every_page']
50
- using_temp(target) do |tmpname|
51
- result = Libis::Format::Tool::PdfSplit.run(source, tmpname, *options)
52
- unless result[:err].empty?
53
- error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
54
- next nil
55
- end
56
- tmpname
49
+ result = Libis::Format::Tool::PdfSplit.run(
50
+ source, target,
51
+ @options.map { |k, v|
52
+ if v.nil?
53
+ nil
54
+ else
55
+ ["--#{k}", v]
56
+ end }.compact.flatten
57
+ )
58
+ unless result[:err].empty?
59
+ error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
60
+ return nil
57
61
  end
62
+ result[:out]
58
63
 
59
64
  end
60
65
 
@@ -0,0 +1,71 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_watermark'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ class PdfWatermarkerHeader < Libis::Format::Converter::Base
12
+
13
+ def self.input_types
14
+ [:PDF]
15
+ end
16
+
17
+ def self.output_types(format = nil)
18
+ return [] unless input_types.include?(format) if format
19
+ [:PDF]
20
+ end
21
+
22
+ def pdf_watermark_header(_)
23
+ #force usage of this converter
24
+ end
25
+
26
+ def initialize
27
+ super
28
+ end
29
+
30
+ def text(v)
31
+ @options[:text] = v.blank? ? nil : v
32
+ end
33
+
34
+ def convert(source, target, format, opts = {})
35
+ super
36
+
37
+ result = convert_pdf(source, target)
38
+ return nil unless result
39
+
40
+ result
41
+
42
+ end
43
+
44
+ # noinspection DuplicatedCode
45
+ def convert_pdf(source, target)
46
+
47
+ using_temp(target) do |tmpname|
48
+ result = Libis::Format::Tool::PdfWatermark.run(
49
+ source, tmpname, 'header',
50
+ @options.map {|k, v|
51
+ if v.nil?
52
+ nil
53
+ else
54
+ ["--#{k}", v]
55
+ end
56
+ }.compact.flatten
57
+ )
58
+ unless result[:err].empty?
59
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
60
+ next nil
61
+ end
62
+ tmpname
63
+ end
64
+
65
+ end
66
+
67
+ end
68
+
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,76 @@
1
+ # encoding: utf-8
2
+
3
+ require_relative 'base'
4
+
5
+ require 'libis/format/tool/pdf_watermark'
6
+
7
+ module Libis
8
+ module Format
9
+ module Converter
10
+
11
+ class PdfWatermarkerImage < Libis::Format::Converter::Base
12
+
13
+ def self.input_types
14
+ [:PDF]
15
+ end
16
+
17
+ def self.output_types(format = nil)
18
+ return [] unless input_types.include?(format) if format
19
+ [:PDF]
20
+ end
21
+
22
+ def pdf_watermark_image(_)
23
+ #force usage of this converter
24
+ end
25
+
26
+ def initialize
27
+ super
28
+ @options[:opacity] = '0.3'
29
+ end
30
+
31
+ def file(v)
32
+ @file = v
33
+ end
34
+
35
+ def opacity(v)
36
+ @options[:opacity] = v unless v.blank?
37
+ end
38
+
39
+ def convert(source, target, format, opts = {})
40
+ super
41
+
42
+ result = convert_pdf(source, target)
43
+ return nil unless result
44
+
45
+ result
46
+
47
+ end
48
+
49
+ # noinspection DuplicatedCode
50
+ def convert_pdf(source, target)
51
+
52
+ using_temp(target) do |tmpname|
53
+ result = Libis::Format::Tool::PdfWatermark.run(
54
+ source, tmpname, 'image',
55
+ @options.map {|k, v|
56
+ if v.nil?
57
+ nil
58
+ else
59
+ ["--#{k}", v]
60
+ end
61
+ }.compact.flatten + [@file]
62
+ )
63
+ unless result[:err].empty?
64
+ error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
65
+ next nil
66
+ end
67
+ tmpname
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
76
+ end
@@ -2,16 +2,13 @@
2
2
 
3
3
  require_relative 'base'
4
4
 
5
- require 'libis/tools/extend/hash'
6
- require 'libis/format/tool/pdf_copy'
7
- require 'libis/format/tool/pdf_to_pdfa'
8
- require 'libis/format/tool/pdf_optimizer'
5
+ require 'libis/format/tool/pdf_watermark'
9
6
 
10
7
  module Libis
11
8
  module Format
12
9
  module Converter
13
10
 
14
- class PdfWatermarker < Libis::Format::Converter::Base
11
+ class PdfWatermarkerText < Libis::Format::Converter::Base
15
12
 
16
13
  def self.input_types
17
14
  [:PDF]
@@ -22,22 +19,18 @@ module Libis
22
19
  [:PDF]
23
20
  end
24
21
 
25
- def pdf_watermark(_)
22
+ def pdf_watermark_text(_)
26
23
  #force usage of this converter
27
24
  end
28
25
 
29
26
  def initialize
30
27
  super
31
- @options[:text] = '© LIBIS'
28
+ @text = []
32
29
  @options[:opacity] = '0.3'
33
30
  end
34
31
 
35
- def file(v)
36
- @options[:file] = v.blank? ? nil : v
37
- end
38
-
39
32
  def text(v)
40
- @options[:text] = v
33
+ @text += v.split("\n")
41
34
  end
42
35
 
43
36
  def rotation(v)
@@ -52,12 +45,12 @@ module Libis
52
45
  @options[:opacity] = v unless v.blank?
53
46
  end
54
47
 
55
- def gap_size(v)
56
- @options[:gap_size] = v
48
+ def gap(v)
49
+ @options[:gap] = v
57
50
  end
58
51
 
59
- def gap_ratio(v)
60
- @options[:gap_ratio] = v
52
+ def padding(v)
53
+ @options[:padding] = v
61
54
  end
62
55
 
63
56
  def convert(source, target, format, opts = {})
@@ -70,29 +63,19 @@ module Libis
70
63
 
71
64
  end
72
65
 
73
- OPTIONS_TABLE = {
74
- file: 'wm_image',
75
- text: 'wm_text',
76
- rotation: 'wm_text_rotation',
77
- size: 'wm_font_size',
78
- opacity: 'wm_opacity',
79
- gap_size: 'wm_gap_size',
80
- gap_ratio: 'wm_gap_ratio'
81
- }
82
66
  # noinspection DuplicatedCode
83
67
  def convert_pdf(source, target)
84
68
 
85
69
  using_temp(target) do |tmpname|
86
- result = Libis::Format::Tool::PdfCopy.run(
87
- source, tmpname,
70
+ result = Libis::Format::Tool::PdfWatermark.run(
71
+ source, tmpname, 'text',
88
72
  @options.map {|k, v|
89
73
  if v.nil?
90
74
  nil
91
75
  else
92
- v = v.split('\n') unless v.blank? if k == :text
93
- k = OPTIONS_TABLE[k] || k
94
- ["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
95
- end}.compact.flatten
76
+ ["--#{k}", v]
77
+ end
78
+ }.compact.flatten + @text
96
79
  )
97
80
  unless result[:err].empty?
98
81
  error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
@@ -12,10 +12,13 @@ module Libis
12
12
  autoload :OfficeToPdf, 'libis/format/tool/office_to_pdf'
13
13
  autoload :FFMpeg, 'libis/format/tool/ffmpeg'
14
14
  autoload :FopPdf, 'libis/format/tool/fop_pdf'
15
- autoload :PdfCopy, 'libis/format/tool/pdf_copy'
16
15
  autoload :PdfMerge, 'libis/format/tool/pdf_merge'
16
+ autoload :PdfMetadata, 'libis/format/tool/pdf_metadata'
17
17
  autoload :PdfOptimizer, 'libis/format/tool/pdf_optimizer'
18
+ autoload :PdfProtect, 'libis/format/tool/pdf_protect'
19
+ autoload :PdfSelect, 'libis/format/tool/pdf_select'
18
20
  autoload :PdfSplit, 'libis/format/tool/pdf_split'
21
+ autoload :PdfWatermark, 'libis/format/tool/pdf_watermark'
19
22
  autoload :PdfToPdfa, 'libis/format/tool/pdf_to_pdfa'
20
23
  autoload :PdfaValidator, 'libis/format/tool/pdfa_validator'
21
24
 
@@ -27,9 +27,9 @@ module Libis
27
27
  timeout = Libis::Format::Config[:timeouts][:pdf_merge]
28
28
  result = Libis::Tools::Command.run(
29
29
  Libis::Format::Config[:java_cmd],
30
- '-cp', Libis::Format::Config[:pdf_tool],
31
- 'MergePdf',
32
- '--file_output', target,
30
+ '-jar', Libis::Format::Config[:pdf_tool],
31
+ 'merge',
32
+ '-o', target,
33
33
  *options,
34
34
  *source,
35
35
  timeout: timeout,
@@ -10,7 +10,7 @@ module Libis
10
10
  module Format
11
11
  module Tool
12
12
 
13
- class PdfCopy
13
+ class PdfMetadata
14
14
  include ::Libis::Tools::Logger
15
15
 
16
16
  def self.run(source, target, options = [])
@@ -26,10 +26,10 @@ module Libis
26
26
  timeout = Libis::Format::Config[:timeouts][:pdf_copy]
27
27
  result = Libis::Tools::Command.run(
28
28
  Libis::Format::Config[:java_cmd],
29
- '-cp', Libis::Format::Config[:pdf_tool],
30
- 'CopyPdf',
31
- '--file_input', source,
32
- '--file_output', target,
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'metadata',
31
+ '-i', source,
32
+ '-o', target,
33
33
  *options,
34
34
  timeout: timeout,
35
35
  kill_after: timeout * 2
@@ -0,0 +1,47 @@
1
+ require 'os'
2
+
3
+ require 'libis/tools/extend/string'
4
+ require 'libis/tools/logger'
5
+ require 'libis/tools/command'
6
+
7
+ require 'libis/format/config'
8
+
9
+ module Libis
10
+ module Format
11
+ module Tool
12
+
13
+ class PdfProtect
14
+ include ::Libis::Tools::Logger
15
+
16
+ def self.run(source, target, options = [])
17
+ self.new.run source, target, options
18
+ end
19
+
20
+ def run(source, target, options = [])
21
+
22
+ if OS.java?
23
+ # TODO: import library and execute in current VM. For now do exactly as in MRI.
24
+ end
25
+
26
+ timeout = Libis::Format::Config[:timeouts][:pdf_copy]
27
+ result = Libis::Tools::Command.run(
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'protect',
31
+ '-i', source,
32
+ '-o', target,
33
+ *options,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
36
+ )
37
+
38
+ raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
+ raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,47 @@
1
+ require 'os'
2
+
3
+ require 'libis/tools/extend/string'
4
+ require 'libis/tools/logger'
5
+ require 'libis/tools/command'
6
+
7
+ require 'libis/format/config'
8
+
9
+ module Libis
10
+ module Format
11
+ module Tool
12
+
13
+ class PdfSelect
14
+ include ::Libis::Tools::Logger
15
+
16
+ def self.run(source, target, options = [])
17
+ self.new.run source, target, options
18
+ end
19
+
20
+ def run(source, target, options = [])
21
+
22
+ if OS.java?
23
+ # TODO: import library and execute in current VM. For now do exactly as in MRI.
24
+ end
25
+
26
+ timeout = Libis::Format::Config[:timeouts][:pdf_select]
27
+ result = Libis::Tools::Command.run(
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'select',
31
+ '-i', source,
32
+ '-o', target,
33
+ *options,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
36
+ )
37
+
38
+ raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
+ raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -26,10 +26,10 @@ module Libis
26
26
  timeout = Libis::Format::Config[:timeouts][:pdf_split]
27
27
  result = Libis::Tools::Command.run(
28
28
  Libis::Format::Config[:java_cmd],
29
- '-cp', Libis::Format::Config[:pdf_tool],
30
- 'SplitPdf',
31
- '--file_input', source,
32
- '--file_output', target,
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'split',
31
+ '-i', source,
32
+ '-o', target,
33
33
  *options,
34
34
  timeout: timeout,
35
35
  kill_after: timeout * 2
@@ -0,0 +1,47 @@
1
+ require 'os'
2
+
3
+ require 'libis/tools/extend/string'
4
+ require 'libis/tools/logger'
5
+ require 'libis/tools/command'
6
+
7
+ require 'libis/format/config'
8
+
9
+ module Libis
10
+ module Format
11
+ module Tool
12
+
13
+ class PdfWatermark
14
+ include ::Libis::Tools::Logger
15
+
16
+ def self.run(source, target, wm_type, options = [])
17
+ self.new.run source, target, wm_type, options
18
+ end
19
+
20
+ def run(source, target, wm_type, options = [])
21
+
22
+ if OS.java?
23
+ # TODO: import library and execute in current VM. For now do exactly as in MRI.
24
+ end
25
+
26
+ timeout = Libis::Format::Config[:timeouts][:pdf_watermark]
27
+ result = Libis::Tools::Command.run(
28
+ Libis::Format::Config[:java_cmd],
29
+ '-jar', Libis::Format::Config[:pdf_tool],
30
+ 'watermark', wm_type,
31
+ '-i', source,
32
+ '-o', target,
33
+ *options,
34
+ timeout: timeout,
35
+ kill_after: timeout * 2
36
+ )
37
+
38
+ raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
39
+ raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
40
+
41
+ result
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  module Libis
2
2
  module Format
3
- VERSION = '2.0.0'
3
+ VERSION = '2.0.1'
4
4
  end
5
5
  end
data/libis-format.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'nokogiri'
34
34
  end
35
35
 
36
- spec.add_runtime_dependency 'libis-tools', '~> 1.0'
36
+ spec.add_runtime_dependency 'libis-tools', '>= 1.0.9'
37
37
  spec.add_runtime_dependency 'os', '= 0.9.6'
38
38
  spec.add_runtime_dependency 'mini_magick', '~> 4.3'
39
39
  spec.add_runtime_dependency 'deep_dive', '~> 0.3'
data/tools/PdfTool.jar CHANGED
Binary file
Binary file
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libis-format
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kris Dekeyser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-09 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -84,16 +84,16 @@ dependencies:
84
84
  name: libis-tools
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - "~>"
87
+ - - ">="
88
88
  - !ruby/object:Gem::Version
89
- version: '1.0'
89
+ version: 1.0.9
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - "~>"
94
+ - - ">="
95
95
  - !ruby/object:Gem::Version
96
- version: '1.0'
96
+ version: 1.0.9
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: os
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -222,9 +222,14 @@ files:
222
222
  - lib/libis/format/converter/office_converter.rb
223
223
  - lib/libis/format/converter/pdf_assembler.rb
224
224
  - lib/libis/format/converter/pdf_converter.rb
225
+ - lib/libis/format/converter/pdf_metadata.rb
225
226
  - lib/libis/format/converter/pdf_optimizer.rb
227
+ - lib/libis/format/converter/pdf_protecter.rb
228
+ - lib/libis/format/converter/pdf_selecter.rb
226
229
  - lib/libis/format/converter/pdf_splitter.rb
227
- - lib/libis/format/converter/pdf_watermarker.rb
230
+ - lib/libis/format/converter/pdf_watermarker_header.rb
231
+ - lib/libis/format/converter/pdf_watermarker_image.rb
232
+ - lib/libis/format/converter/pdf_watermarker_text.rb
228
233
  - lib/libis/format/converter/repository.rb
229
234
  - lib/libis/format/converter/spreadsheet_converter.rb
230
235
  - lib/libis/format/converter/video_converter.rb
@@ -241,19 +246,22 @@ files:
241
246
  - lib/libis/format/tool/fop_pdf.rb
242
247
  - lib/libis/format/tool/identification_tool.rb
243
248
  - lib/libis/format/tool/office_to_pdf.rb
244
- - lib/libis/format/tool/pdf_copy.rb
245
249
  - lib/libis/format/tool/pdf_merge.rb
250
+ - lib/libis/format/tool/pdf_metadata.rb
246
251
  - lib/libis/format/tool/pdf_optimizer.rb
252
+ - lib/libis/format/tool/pdf_protect.rb
253
+ - lib/libis/format/tool/pdf_select.rb
247
254
  - lib/libis/format/tool/pdf_split.rb
248
255
  - lib/libis/format/tool/pdf_to_pdfa.rb
256
+ - lib/libis/format/tool/pdf_watermark.rb
249
257
  - lib/libis/format/tool/pdfa_validator.rb
250
258
  - lib/libis/format/tool/spreadsheet_to_ods.rb
251
259
  - lib/libis/format/version.rb
252
260
  - lib/libis/format/yaml_loader.rb
253
261
  - libis-format.gemspec
254
262
  - tools/PdfTool.jar
255
- - tools/bcpkix-jdk15on-1.49.jar
256
- - tools/bcprov-jdk15on-1.49.jar
263
+ - tools/bcpkix-jdk15on-167.jar
264
+ - tools/bcprov-jdk15on-167.jar
257
265
  - tools/fop/build/fop.jar
258
266
  - tools/fop/conf/fop.xconf
259
267
  - tools/fop/fop
@@ -325,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
325
333
  - !ruby/object:Gem::Version
326
334
  version: '0'
327
335
  requirements: []
328
- rubygems_version: 3.0.8
336
+ rubygems_version: 3.1.4
329
337
  signing_key:
330
338
  specification_version: 4
331
339
  summary: LIBIS File format format services.
Binary file
Binary file