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.
- 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
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cad4173d3e5cc43e573f612cc3f345ef91f5eb8938bb0d457681514d281a531
|
4
|
+
data.tar.gz: 77e84828a1269bb9ddd153362a8af2221153494542f328b73785d014740e07e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc76923e13c732a606af376614b9d2dd716e7ff851a77645bc8fd979ee7d7c6e98c5bd9936ea506f68009c1aba71b94be98a558e7b4167e53011d966a099c2e
|
7
|
+
data.tar.gz: 29c46dc0a855ff168d2160cd9934e6a710d98e1ddea3b06ae47413248f3d1ddc288bbf376a89a85505ca10cba6d3b3b1d80b4f50f8a1545389b9671f9a0fa46d
|
data/.gitignore
CHANGED
data/bin/{droid → droid_tool}
RENAMED
File without changes
|
data/bin/{fido → fido_tool}
RENAMED
File without changes
|
data/lib/libis/format.rb
CHANGED
data/lib/libis/format/config.rb
CHANGED
@@ -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:
|
33
|
+
ffmpeg: 500 * 60,
|
34
34
|
fido: 20 * 60,
|
35
|
-
file_tool:
|
36
|
-
fop:
|
37
|
-
identification_tool:
|
38
|
-
office_to_pdf:
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
@@ -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
|
@@ -51,11 +51,13 @@ module Libis
|
|
51
51
|
@options[:progression_order] = value
|
52
52
|
end
|
53
53
|
|
54
|
-
def tile_size(width = 1024, height =
|
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(
|
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/
|
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
|
-
[:
|
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 =
|
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
|
@@ -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
|