libis-format 2.0.0 → 2.0.5
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 +4 -4
- data/.gitignore +2 -0
- data/bin/{droid → droid_tool} +0 -0
- data/bin/{fido → fido_tool} +0 -0
- data/lib/libis/format.rb +7 -1
- data/lib/libis/format/config.rb +13 -11
- data/lib/libis/format/converter/audio_converter.rb +6 -6
- data/lib/libis/format/converter/base.rb +1 -0
- data/lib/libis/format/converter/image_converter.rb +1 -1
- data/lib/libis/format/converter/image_splitter.rb +4 -0
- data/lib/libis/format/converter/jp2_converter.rb +4 -2
- data/lib/libis/format/converter/pdf_converter.rb +4 -72
- data/lib/libis/format/converter/pdf_metadata.rb +82 -0
- data/lib/libis/format/converter/pdf_optimizer.rb +0 -3
- data/lib/libis/format/converter/pdf_protecter.rb +147 -0
- data/lib/libis/format/converter/pdf_selecter.rb +83 -0
- data/lib/libis/format/converter/pdf_splitter.rb +20 -15
- data/lib/libis/format/converter/pdf_watermarker_header.rb +71 -0
- data/lib/libis/format/converter/pdf_watermarker_image.rb +76 -0
- data/lib/libis/format/converter/{pdf_watermarker.rb → pdf_watermarker_text.rb} +14 -31
- data/lib/libis/format/converter/video_converter.rb +22 -22
- data/lib/libis/format/tool.rb +4 -1
- data/lib/libis/format/tool/pdf_merge.rb +3 -3
- data/lib/libis/format/tool/{pdf_copy.rb → pdf_metadata.rb} +5 -5
- data/lib/libis/format/tool/pdf_protect.rb +47 -0
- data/lib/libis/format/tool/pdf_select.rb +47 -0
- data/lib/libis/format/tool/pdf_split.rb +4 -4
- data/lib/libis/format/tool/pdf_watermark.rb +47 -0
- data/lib/libis/format/version.rb +1 -1
- data/libis-format.gemspec +1 -1
- data/tools/PdfTool.jar +0 -0
- data/tools/bcpkix-jdk15on-167.jar +0 -0
- data/tools/bcprov-jdk15on-167.jar +0 -0
- metadata +23 -17
- data/bin/pdf_copy +0 -13
- data/tools/bcpkix-jdk15on-1.49.jar +0 -0
- data/tools/bcprov-jdk15on-1.49.jar +0 -0
@@ -0,0 +1,83 @@
|
|
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[:ranges] = []
|
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[:ranges] += selection.split(/\s*,\s*/) unless selection.blank?
|
36
|
+
end
|
37
|
+
|
38
|
+
# Select a partial list of pages
|
39
|
+
# @param [String|Array<String>] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
|
40
|
+
def ranges(selection)
|
41
|
+
case selection
|
42
|
+
when Array
|
43
|
+
@options[:ranges] += selection.to_s unless selection.empty?
|
44
|
+
when String
|
45
|
+
range([selection])
|
46
|
+
else
|
47
|
+
# nothing
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def convert(source, target, format, opts = {})
|
52
|
+
super
|
53
|
+
|
54
|
+
result = nil
|
55
|
+
|
56
|
+
unless @options.empty?
|
57
|
+
result = convert_pdf(source, target)
|
58
|
+
return nil unless result
|
59
|
+
end
|
60
|
+
|
61
|
+
result
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
def convert_pdf(source, target)
|
66
|
+
|
67
|
+
using_temp(target) do |tmpname|
|
68
|
+
opts = @options[:ranges].map { |range| ["-r", range] }.compact.flatten
|
69
|
+
result = Libis::Format::Tool::PdfSelect.run(source, tmpname, opts)
|
70
|
+
unless result[:err].empty?
|
71
|
+
error("Pdf selection encountered errors:\n%s", result[:err].join(join("\n")))
|
72
|
+
next nil
|
73
|
+
end
|
74
|
+
tmpname
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
83
|
+
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
|
-
[:
|
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
|
-
|
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
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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.to_s]
|
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.to_s]
|
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.to_s]
|
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/
|
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
|
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
|
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
|
-
@
|
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
|
-
@
|
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
|
56
|
-
@options[:
|
48
|
+
def gap(v)
|
49
|
+
@options[:gap] = v
|
57
50
|
end
|
58
51
|
|
59
|
-
def
|
60
|
-
@options[:
|
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::
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end}.compact.flatten
|
76
|
+
["--#{k}", v.to_s]
|
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")))
|
@@ -31,7 +31,7 @@ module Libis
|
|
31
31
|
end
|
32
32
|
|
33
33
|
def audio_channels(value)
|
34
|
-
@options[:audio_channels] = value
|
34
|
+
@options[:audio_channels] = value
|
35
35
|
end
|
36
36
|
|
37
37
|
def audio_codec(codec)
|
@@ -43,39 +43,39 @@ module Libis
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def start(seconds)
|
46
|
-
@options[:start] = seconds
|
46
|
+
@options[:start] = seconds
|
47
47
|
end
|
48
48
|
|
49
49
|
def duration(seconds)
|
50
|
-
@options[:duration] = seconds
|
50
|
+
@options[:duration] = seconds
|
51
51
|
end
|
52
52
|
|
53
53
|
def audio_quality(value)
|
54
|
-
@options[:audio_quality] = value
|
54
|
+
@options[:audio_quality] = value
|
55
55
|
end
|
56
56
|
|
57
57
|
def video_quality(value)
|
58
|
-
@options[:video_quality] = value
|
58
|
+
@options[:video_quality] = value
|
59
59
|
end
|
60
60
|
|
61
61
|
def audio_bitrate(value)
|
62
|
-
@options[:audio_bitrate] = value
|
62
|
+
@options[:audio_bitrate] = value
|
63
63
|
end
|
64
64
|
|
65
65
|
def video_bitrate(value)
|
66
|
-
@options[:video_bitrate] = value
|
66
|
+
@options[:video_bitrate] = value
|
67
67
|
end
|
68
68
|
|
69
69
|
def constant_rate_factor(value)
|
70
|
-
@options[:crf] = value
|
70
|
+
@options[:crf] = value
|
71
71
|
end
|
72
72
|
|
73
73
|
def frame_rate(value)
|
74
|
-
@options[:frame_rate] = value
|
74
|
+
@options[:frame_rate] = value
|
75
75
|
end
|
76
76
|
|
77
77
|
def sampling_freq(value)
|
78
|
-
@options[:sampling_freq] = value
|
78
|
+
@options[:sampling_freq] = value
|
79
79
|
end
|
80
80
|
|
81
81
|
def scale(width_x_height)
|
@@ -239,21 +239,21 @@ module Libis
|
|
239
239
|
] if @options[:watermark_text_shadow_offset] > 0
|
240
240
|
opts[:filter] << '-vf' << filter_text
|
241
241
|
end
|
242
|
-
opts[:output] << '-ac' << @options[:audio_channels] if @options[:audio_channels]
|
243
|
-
opts[:output] << '-c:a' << @options[:audio_codec] if @options[:audio_codec]
|
244
|
-
opts[:output] << '-c:v' << @options[:video_codec] if @options[:video_codec]
|
245
|
-
opts[:output] << '-b:a' << @options[:audio_bitrate] if @options[:audio_bitrate]
|
246
|
-
opts[:output] << '-b:v' << @options[:video_bitrate] if @options[:video_bitrate]
|
247
|
-
opts[:output] << '-crf' << @options[:crf] if @options[:crf]
|
242
|
+
opts[:output] << '-ac' << @options[:audio_channels].to_s if @options[:audio_channels]
|
243
|
+
opts[:output] << '-c:a' << @options[:audio_codec].to_s if @options[:audio_codec]
|
244
|
+
opts[:output] << '-c:v' << @options[:video_codec].to_s if @options[:video_codec]
|
245
|
+
opts[:output] << '-b:a' << @options[:audio_bitrate].to_s if @options[:audio_bitrate]
|
246
|
+
opts[:output] << '-b:v' << @options[:video_bitrate].to_s if @options[:video_bitrate]
|
247
|
+
opts[:output] << '-crf' << @options[:crf].to_s if @options[:crf]
|
248
248
|
opts[:output] << '-map_metadata:g' << '0:g' # Copy global metadata
|
249
249
|
opts[:output] << '-map_metadata:s:a' << '0:s:a' # Copy audio metadata
|
250
250
|
opts[:output] << '-map_metadata:s:v' << '0:s:v' # Copy video metadata
|
251
|
-
opts[:input] << '-accurate_seek' << (@options[:start].to_i < 0 ? '-sseof' : '-ss') << @options[:start] if @options[:start]
|
252
|
-
opts[:input] << '-t' << @options[:duration] if @options[:duration]
|
253
|
-
opts[:output] << '-qscale' << @options[:video_quality] if @options[:video_quality]
|
254
|
-
opts[:output] << '-q:a' << @options[:audio_quality] if @options[:audio_quality]
|
255
|
-
opts[:output] << '-r' << @options[:frame_rate] if @options[:frame_rate]
|
256
|
-
opts[:output] << '-ar' << @options[:sampling_freq] if @options[:sampling_freq]
|
251
|
+
opts[:input] << '-accurate_seek' << (@options[:start].to_i < 0 ? '-sseof' : '-ss') << @options[:start].to_s if @options[:start]
|
252
|
+
opts[:input] << '-t' << @options[:duration].to_s if @options[:duration]
|
253
|
+
opts[:output] << '-qscale' << @options[:video_quality].to_s if @options[:video_quality]
|
254
|
+
opts[:output] << '-q:a' << @options[:audio_quality].to_s if @options[:audio_quality]
|
255
|
+
opts[:output] << '-r' << @options[:frame_rate].to_s if @options[:frame_rate]
|
256
|
+
opts[:output] << '-ar' << @options[:sampling_freq].to_s if @options[:sampling_freq]
|
257
257
|
if @options[:scale]
|
258
258
|
scale = @options[:scale].split('x')
|
259
259
|
width = scale[0]
|