libis-format 2.0.0 → 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/bin/{droid → droid_tool} +0 -0
  4. data/bin/{fido → fido_tool} +0 -0
  5. data/lib/libis/format.rb +7 -1
  6. data/lib/libis/format/config.rb +13 -11
  7. data/lib/libis/format/converter/audio_converter.rb +6 -6
  8. data/lib/libis/format/converter/base.rb +1 -0
  9. data/lib/libis/format/converter/image_converter.rb +1 -1
  10. data/lib/libis/format/converter/image_splitter.rb +4 -0
  11. data/lib/libis/format/converter/jp2_converter.rb +4 -2
  12. data/lib/libis/format/converter/pdf_converter.rb +4 -72
  13. data/lib/libis/format/converter/pdf_metadata.rb +82 -0
  14. data/lib/libis/format/converter/pdf_optimizer.rb +0 -3
  15. data/lib/libis/format/converter/pdf_protecter.rb +147 -0
  16. data/lib/libis/format/converter/pdf_selecter.rb +83 -0
  17. data/lib/libis/format/converter/pdf_splitter.rb +20 -15
  18. data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
  19. data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
  20. data/lib/libis/format/converter/{pdf_watermarker.rb → pdf_watermarker_text.rb} +14 -31
  21. data/lib/libis/format/converter/video_converter.rb +22 -22
  22. data/lib/libis/format/tool.rb +4 -1
  23. data/lib/libis/format/tool/pdf_merge.rb +3 -3
  24. data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +5 -5
  25. data/lib/libis/format/tool/pdf_protect.rb +47 -0
  26. data/lib/libis/format/tool/pdf_select.rb +47 -0
  27. data/lib/libis/format/tool/pdf_split.rb +4 -4
  28. data/lib/libis/format/tool/pdf_watermark.rb +47 -0
  29. data/lib/libis/format/version.rb +1 -1
  30. data/libis-format.gemspec +1 -1
  31. data/tools/PdfTool.jar +0 -0
  32. data/tools/bcpkix-jdk15on-167.jar +0 -0
  33. data/tools/bcprov-jdk15on-167.jar +0 -0
  34. metadata +23 -17
  35. data/bin/pdf_copy +0 -13
  36. data/tools/bcpkix-jdk15on-1.49.jar +0 -0
  37. data/tools/bcprov-jdk15on-1.49.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f563ad694fd3d0c9e4a9f0da3309c99ac4b103e6027fcc9cda1606f0f67549c2
4
- data.tar.gz: 5cee3f4b3bb1e51db492ee14bf919b0ce0fa69e267292380364c32b4eec40b4e
3
+ metadata.gz: 7cad4173d3e5cc43e573f612cc3f345ef91f5eb8938bb0d457681514d281a531
4
+ data.tar.gz: 77e84828a1269bb9ddd153362a8af2221153494542f328b73785d014740e07e1
5
5
  SHA512:
6
- metadata.gz: 409ea1fac8f8be4d2519f189090207b6a550a1b1ce174a71fa1886c69b667001459d4bdccd850dd55373199ae5553ebd02183e15eebc88a73d0ac3f8093f7d12
7
- data.tar.gz: d3e4d77ddcaab1f5050aaf4acb02e74a221566abedb94062254efbc24d18703c8fdd739644b1cd5435b54a4497e77c82bdcbcb218d121bfaf135e483662aca06
6
+ metadata.gz: 1cc76923e13c732a606af376614b9d2dd716e7ff851a77645bc8fd979ee7d7c6e98c5bd9936ea506f68009c1aba71b94be98a558e7b4167e53011d966a099c2e
7
+ data.tar.gz: 29c46dc0a855ff168d2160cd9934e6a710d98e1ddea3b06ae47413248f3d1ddc288bbf376a89a85505ca10cba6d3b3b1d80b4f50f8a1545389b9671f9a0fa46d
data/.gitignore CHANGED
@@ -18,3 +18,5 @@ mkmf.log
18
18
  *.pyc
19
19
  tools/pdf/
20
20
  /test*
21
+ /*~
22
+ /*.pdf
File without changes
File without changes
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
@@ -30,18 +30,20 @@ module Libis
30
30
  Config[:watermark_font] = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf'
31
31
  Config[:timeouts] = {
32
32
  droid: 20 * 60,
33
- ffmpeg: 5 * 60,
33
+ ffmpeg: 500 * 60,
34
34
  fido: 20 * 60,
35
- file_tool: 5 * 60,
36
- fop: 5 * 60,
37
- identification_tool: 5 * 60,
38
- office_to_pdf: 5 * 60,
39
- pdf_copy: 5 * 60,
40
- pdf_merge: 5 * 60,
41
- pdf_optimizer: 5 * 60,
42
- pdf_split: 5 * 60,
43
- pdf_to_pdfa: 5 * 60,
44
- pdfa_validator: 5 * 60,
35
+ file_tool: 20 * 60,
36
+ fop: 50 * 60,
37
+ identification_tool: 50 * 60,
38
+ office_to_pdf: 50 * 60,
39
+ pdf_select: 50 * 60,
40
+ pdf_copy: 50 * 60,
41
+ pdf_merge: 50 * 60,
42
+ pdf_optimizer: 50 * 60,
43
+ pdf_split: 50 * 60,
44
+ pdf_watermark: 50 * 60,
45
+ pdf_to_pdfa: 50 * 60,
46
+ pdfa_validator: 50 * 60,
45
47
  }
46
48
 
47
49
  end
@@ -128,12 +128,12 @@ module Libis
128
128
  opts[:output] << '-map_metadata:g' << '0:g' # Copy global metadata
129
129
  opts[:output] << '-map_metadata:s:a' << '0:s:a' # Copy audio metadata
130
130
  opts[:input] << '-accurate_seek' << (@options[:start].to_i < 0 ? '-sseof' : '-ss') << @options[:start] if @options[:start]
131
- opts[:input] << '-t' << @options[:duration] if @options[:duration]
132
- opts[:output] << '-q:a' << @options[:quality] if @options[:quality]
133
- opts[:output] << '-b:a' << @options[:bit_rate] if @options[:bit_rate]
134
- opts[:output] << '-ar' << @options[:sampling_freq] if @options[:sampling_freq]
135
- opts[:output] << '-ac' << @options[:channels] if @options[:channels]
136
- opts[:output] << '-f' << @options[:format] if @options[:format]
131
+ opts[:input] << '-t' << @options[:duration].to_s if @options[:duration]
132
+ opts[:output] << '-q:a' << @options[:quality].to_s if @options[:quality]
133
+ opts[:output] << '-b:a' << @options[:bit_rate].to_s if @options[:bit_rate]
134
+ opts[:output] << '-ar' << @options[:sampling_freq].to_s if @options[:sampling_freq]
135
+ opts[:output] << '-ac' << @options[:channels].to_s if @options[:channels]
136
+ opts[:output] << '-f' << @options[:format].to_s if @options[:format]
137
137
  result = Libis::Format::Tool::FFMpeg.run(source, target, opts)
138
138
  info "FFMpeg output: #{result}"
139
139
  result
@@ -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'
@@ -130,7 +130,7 @@ module Libis
130
130
  colorspace = @options.delete(:colorspace) || 'sRGB'
131
131
  unless @options.empty?
132
132
  convert.colorspace('RGB')
133
- @options.each {|o, v| convert.send(o, v)}
133
+ @options.each {|o, v| convert.send(o, v.to_s)}
134
134
  end
135
135
  convert.colorspace(colorspace)
136
136
  convert.profile @profile if @profile
@@ -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
@@ -51,11 +51,13 @@ module Libis
51
51
  @options[:progression_order] = value
52
52
  end
53
53
 
54
- def tile_size(width = 1024, height = 1024)
54
+ def tile_size(width = 1024, height = nil)
55
+ height ||= width
55
56
  @options[:tile_size] = [width, height]
56
57
  end
57
58
 
58
- def codeblock_size(height = 6, width = 6)
59
+ def codeblock_size(width = 6, height = nil)
60
+ height ||= width
59
61
  @options[:codeblock_size] = [height, width]
60
62
  end
61
63
 
@@ -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.to_s]
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.to_s]
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