libis-format 1.3.4 → 2.0.0
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/.coveralls.yml +2 -0
- data/.gitignore +20 -0
- data/.travis.yml +70 -0
- data/Gemfile +0 -12
- data/README.md +2 -2
- data/Rakefile +8 -0
- data/base/Dockerfile +35 -0
- data/base/Dockerfile.alpine +20 -0
- data/base/Dockerfile.rvm +56 -0
- data/base/rework_path +20 -0
- data/bin/{pdf_tool → pdf_copy} +2 -3
- data/data/PDFA_def.ps +3 -3
- data/data/eciRGB_v2.icc +0 -0
- data/data/types.yml +4 -17
- data/docker_cfg.yml +1 -0
- data/lib/libis/format/cli/convert.rb +4 -4
- data/lib/libis/format/cli/prompt_helper.rb +24 -32
- data/lib/libis/format/command_line.rb +3 -2
- data/lib/libis/format/config.rb +23 -19
- data/lib/libis/format/converter/audio_converter.rb +31 -56
- data/lib/libis/format/converter/base.rb +36 -16
- data/lib/libis/format/converter/chain.rb +32 -52
- data/lib/libis/format/converter/fop_pdf_converter.rb +8 -4
- data/lib/libis/format/converter/image_assembler.rb +82 -0
- data/lib/libis/format/converter/image_converter.rb +45 -250
- data/lib/libis/format/converter/image_splitter.rb +80 -0
- data/lib/libis/format/converter/image_watermarker.rb +261 -0
- data/lib/libis/format/converter/jp2_converter.rb +38 -36
- data/lib/libis/format/converter/office_converter.rb +28 -22
- data/lib/libis/format/converter/pdf_assembler.rb +66 -0
- data/lib/libis/format/converter/pdf_converter.rb +52 -200
- data/lib/libis/format/converter/pdf_optimizer.rb +70 -0
- data/lib/libis/format/converter/pdf_splitter.rb +65 -0
- data/lib/libis/format/converter/pdf_watermarker.rb +110 -0
- data/lib/libis/format/converter/repository.rb +13 -7
- data/lib/libis/format/converter/spreadsheet_converter.rb +16 -10
- data/lib/libis/format/converter/video_converter.rb +58 -47
- data/lib/libis/format/converter/xslt_converter.rb +11 -13
- data/lib/libis/format/converter.rb +1 -1
- data/lib/libis/format/identifier.rb +46 -44
- data/lib/libis/format/info.rb +27 -0
- data/lib/libis/format/library.rb +147 -0
- data/lib/libis/format/tool/droid.rb +30 -29
- data/lib/libis/format/tool/extension_identification.rb +26 -24
- data/lib/libis/format/tool/{ff_mpeg.rb → ffmpeg.rb} +10 -17
- data/lib/libis/format/tool/fido.rb +27 -22
- data/lib/libis/format/tool/file_tool.rb +24 -11
- data/lib/libis/format/tool/fop_pdf.rb +14 -25
- data/lib/libis/format/tool/identification_tool.rb +40 -38
- data/lib/libis/format/tool/office_to_pdf.rb +18 -30
- data/lib/libis/format/tool/pdf_copy.rb +47 -0
- data/lib/libis/format/tool/pdf_merge.rb +19 -25
- data/lib/libis/format/tool/pdf_optimizer.rb +19 -22
- data/lib/libis/format/tool/pdf_split.rb +33 -6
- data/lib/libis/format/tool/pdf_to_pdfa.rb +31 -45
- data/lib/libis/format/tool/pdfa_validator.rb +30 -24
- data/lib/libis/format/tool/spreadsheet_to_ods.rb +18 -29
- data/lib/libis/format/tool.rb +3 -4
- data/lib/libis/format/version.rb +1 -3
- data/lib/libis/format/yaml_loader.rb +71 -0
- data/lib/libis/format.rb +7 -5
- data/lib/libis-format.rb +0 -2
- data/libis-format.gemspec +18 -24
- data/tools/PdfTool.jar +0 -0
- data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
- data/tools/pdfbox/{preflight-app-3.0.3.jar → preflight-app-2.0.13.jar} +0 -0
- metadata +86 -128
- data/data/AdobeRGB1998.icc +0 -0
- data/lib/libis/format/converter/email_converter.rb +0 -35
- data/lib/libis/format/tool/msg_to_pdf.rb +0 -270
- data/lib/libis/format/tool/pdf_tool.rb +0 -52
- data/lib/libis/format/type_database.rb +0 -156
- data/lib/libis/format/type_database_impl.rb +0 -153
- data/tools/pdf2pdfa +0 -395
- data/tools/pdfbox/pdfbox-app-3.0.3.jar +0 -0
- /data/bin/{droid_tool → droid} +0 -0
- /data/bin/{fido_tool → fido} +0 -0
@@ -1,143 +1,52 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
4
|
|
5
5
|
require 'libis/tools/extend/hash'
|
6
|
-
require 'libis/format/tool/
|
6
|
+
require 'libis/format/tool/pdf_copy'
|
7
7
|
require 'libis/format/tool/pdf_to_pdfa'
|
8
|
-
require 'libis/format/tool/pdfa_validator'
|
9
8
|
require 'libis/format/tool/pdf_optimizer'
|
10
9
|
|
11
10
|
module Libis
|
12
11
|
module Format
|
13
12
|
module Converter
|
13
|
+
|
14
|
+
# noinspection DuplicatedCode
|
14
15
|
class PdfConverter < Libis::Format::Converter::Base
|
16
|
+
|
15
17
|
def self.input_types
|
16
18
|
[:PDF]
|
17
19
|
end
|
18
20
|
|
19
21
|
def self.output_types(format = nil)
|
20
|
-
return [] unless input_types.include?(format)
|
21
|
-
|
22
|
-
%i[PDF PDFA]
|
23
|
-
end
|
24
|
-
|
25
|
-
def pdf_convert(_)
|
26
|
-
# force usage of this converter
|
27
|
-
end
|
28
|
-
|
29
|
-
# Set metadata for Pdf file
|
30
|
-
#
|
31
|
-
# valid metadata keys are):
|
32
|
-
# - title
|
33
|
-
# - author
|
34
|
-
# - creator
|
35
|
-
# - keywords
|
36
|
-
# - subject
|
37
|
-
#
|
38
|
-
# @param [Hash] values list of metadata values to set
|
39
|
-
def metadata(values = {})
|
40
|
-
values.key_strings_to_symbols!
|
41
|
-
values.each do |k, v|
|
42
|
-
next unless %i[title author creator keywords subject].include?(k)
|
43
|
-
(@options[:metadata] ||= {})[k] = v
|
44
|
-
end
|
22
|
+
return [] unless input_types.include?(format) if format
|
23
|
+
[:PDF, :PDFA]
|
45
24
|
end
|
46
25
|
|
47
|
-
|
48
|
-
|
49
|
-
def range(selection)
|
50
|
-
@options[:select] = {range: [selection].flatten.compact.join(',')}
|
26
|
+
def title(v)
|
27
|
+
@options[:title] = v.blank? ? nil : v
|
51
28
|
end
|
52
29
|
|
53
|
-
|
54
|
-
|
55
|
-
# The watermark options are (use symbols):
|
56
|
-
# - text: text to create a watermark from
|
57
|
-
# - file: watermark image to use
|
58
|
-
# - image: same as above
|
59
|
-
# - rotation: rotation of the watermark text (in degrees; integer number)
|
60
|
-
# - size: font size of the watermark text
|
61
|
-
# - opacity: opacity of the watermark (fraction 0.0 - 1.0)
|
62
|
-
# - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch).
|
63
|
-
# Fractions are percentage of widht/height.
|
64
|
-
# If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
|
65
|
-
# file will be created or overwritten with a newly created watermark image.
|
66
|
-
#
|
67
|
-
# The created watermark file will be a PNG image with transparent background containing the supplied text
|
68
|
-
# slanted by 30 degrees counter-clockwise.
|
69
|
-
#
|
70
|
-
# @param [Hash] options Hash of options for watermark creation.
|
71
|
-
def watermark(options = {})
|
72
|
-
options.key_strings_to_symbols!
|
73
|
-
if options[:file] || options[:image]
|
74
|
-
watermark_image(options)
|
75
|
-
elsif options[:text]
|
76
|
-
watermark_text(options)
|
77
|
-
elsif options[:banner]
|
78
|
-
watermark_banner(options)
|
79
|
-
end
|
30
|
+
def author(v)
|
31
|
+
@options[:author] = v.blank? ? nil : v
|
80
32
|
end
|
81
33
|
|
82
|
-
def
|
83
|
-
options.
|
84
|
-
@options[:watermark] = {command: 'image'}
|
85
|
-
@options[:watermark][:data] = options[:file] || options[:image]
|
86
|
-
@options[:watermark][:opacity] = options[:opacity] || '0.3'
|
87
|
-
|
34
|
+
def creator(v)
|
35
|
+
@options[:creator] = v.blank? ? nil : v
|
88
36
|
end
|
89
37
|
|
90
|
-
def
|
91
|
-
options.
|
92
|
-
@options[:watermark] = {command: 'text'}
|
93
|
-
@options[:watermark][:data] = (options[:text] || '© LIBIS').split('\n')
|
94
|
-
@options[:watermark][:rotation] = options[:rotation] if options[:rotation]
|
95
|
-
@options[:watermark][:size] = options[:size] if options[:size]
|
96
|
-
@options[:watermark][:gap] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
|
97
|
-
@options[:watermark][:padding] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
|
98
|
-
@options[:watermark][:padding] = options[:padding] if options[:padding]
|
99
|
-
@options[:watermark][:opacity] = options[:opacity] || '0.3'
|
38
|
+
def keywords(v)
|
39
|
+
@options[:keywords] = v.blank? ? nil : v
|
100
40
|
end
|
101
41
|
|
102
|
-
|
103
|
-
|
104
|
-
# The banner options are:
|
105
|
-
# - banner: text to put in the banner
|
106
|
-
# - add_filename: append filename to the text (use any value to enable)
|
107
|
-
# - fontsize: size of the font (in points)
|
108
|
-
# - width: width of the banner
|
109
|
-
# - (background|text)_color_(red|green|blue): color components of background and text
|
110
|
-
def watermark_banner(options = {})
|
111
|
-
options.key_strings_to_symbols!
|
112
|
-
@options[:watermark] = {command: 'banner'}
|
113
|
-
@options[:watermark][:data] = (options[:banner] || '© LIBIS')
|
114
|
-
@options[:watermark][:add_filename] = !!options[:add_filename]
|
115
|
-
@options[:watermark][:size] = options[:fontsize] if options[:fontsize]
|
116
|
-
@options[:watermark][:width] = options[:width] if options[:width]
|
117
|
-
@options[:watermark][:background_red] = options[:background_color_red] if options[:background_color_red]
|
118
|
-
@options[:watermark][:background_green] = options[:background_color_green] if options[:background_color_green]
|
119
|
-
@options[:watermark][:background_blue] = options[:background_color_blue] if options[:background_color_blue]
|
120
|
-
@options[:watermark][:text_red] = options[:text_color_red] if options[:text_color_red]
|
121
|
-
@options[:watermark][:text_green] = options[:text_color_green] if options[:text_color_green]
|
122
|
-
@options[:watermark][:text_blue] = options[:text_color_blue] if options[:text_color_blue]
|
42
|
+
def subject(v)
|
43
|
+
@options[:subject] = v.blank? ? nil : v
|
123
44
|
end
|
124
45
|
|
125
|
-
#
|
126
|
-
#
|
127
|
-
|
128
|
-
|
129
|
-
#
|
130
|
-
# - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
|
131
|
-
# - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
|
132
|
-
# - 2 : good quality (Acrobat Distiller 'Default' equivalent)
|
133
|
-
# - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
|
134
|
-
# - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
|
135
|
-
#
|
136
|
-
# Note that the optimization is intended to be used with PDF's containing high-resolution images.
|
137
|
-
#
|
138
|
-
# @param [Integer] setting quality setting. [0-4]
|
139
|
-
def optimize(setting = 1)
|
140
|
-
@options[:optimize] = %w[screen ebook default printer prepress][setting] if (0..4).include?(setting)
|
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
|
141
50
|
end
|
142
51
|
|
143
52
|
def convert(source, target, format, opts = {})
|
@@ -147,122 +56,65 @@ module Libis
|
|
147
56
|
|
148
57
|
unless @options.empty?
|
149
58
|
result = convert_pdf(source, target)
|
59
|
+
return nil unless result
|
150
60
|
source = result
|
151
61
|
end
|
152
62
|
|
153
|
-
if
|
154
|
-
result = optimize_pdf(source, target, quality)
|
155
|
-
source = result
|
156
|
-
end
|
157
|
-
|
158
|
-
if source && (format == :PDFA)
|
63
|
+
if format == :PDFA and source
|
159
64
|
result = pdf_to_pdfa(source, target)
|
160
65
|
end
|
161
66
|
|
162
|
-
|
163
|
-
files: [result],
|
164
|
-
converter: self.class.name
|
165
|
-
}
|
166
|
-
end
|
167
|
-
|
168
|
-
protected
|
67
|
+
result
|
169
68
|
|
170
|
-
def optimize_pdf(source, target, quality)
|
171
|
-
using_temp(target) do |tmpname|
|
172
|
-
result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
|
173
|
-
unless result[:err].empty?
|
174
|
-
error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
|
175
|
-
return nil
|
176
|
-
end
|
177
|
-
tmpname
|
178
|
-
end
|
179
69
|
end
|
180
70
|
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
def options_to_args(options)
|
190
|
-
options.map do |k, v|
|
191
|
-
key = "--#{k.to_s.tr_s('_', '-')}"
|
192
|
-
value = v
|
193
|
-
case value
|
194
|
-
when TrueClass
|
195
|
-
value = nil
|
196
|
-
when FalseClass
|
197
|
-
value = key = nil
|
198
|
-
when Array
|
199
|
-
value = value.map(&:to_s)
|
200
|
-
else
|
201
|
-
value = v.to_s
|
202
|
-
end
|
203
|
-
[key, value]
|
204
|
-
end.flatten.compact
|
205
|
-
end
|
206
|
-
|
207
|
-
def add_watermark(source, target, options)
|
208
|
-
command = options.delete(:command)
|
209
|
-
data = [options.delete(:data)].flatten.compact
|
210
|
-
args = data + options_to_args(options)
|
211
|
-
|
212
|
-
using_temp(target) do |tmpname|
|
213
|
-
result = Libis::Format::Tool::PdfTool.run(['watermark', command], source, tmpname, *args)
|
214
|
-
unless result[:err].empty?
|
215
|
-
error("Pdf watermarking encountered errors:\n%s", result[:err].join(join("\n")))
|
216
|
-
return nil
|
217
|
-
end
|
218
|
-
tmpname
|
219
|
-
end
|
220
|
-
end
|
71
|
+
OPTIONS_TABLE = {
|
72
|
+
title: 'md_title',
|
73
|
+
author: 'md_author',
|
74
|
+
creator: 'md_creator',
|
75
|
+
keywords: 'md_keywords',
|
76
|
+
subject: 'md_subject'
|
77
|
+
}
|
221
78
|
|
222
|
-
def
|
223
|
-
args = options_to_args(options)
|
79
|
+
def convert_pdf(source, target)
|
224
80
|
|
225
81
|
using_temp(target) do |tmpname|
|
226
|
-
result = Libis::Format::Tool::
|
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
|
+
)
|
227
92
|
unless result[:err].empty?
|
228
|
-
error("Pdf
|
229
|
-
|
93
|
+
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
94
|
+
next nil
|
230
95
|
end
|
231
96
|
tmpname
|
232
97
|
end
|
233
|
-
end
|
234
98
|
|
235
|
-
def select_range(source, target, options)
|
236
|
-
args = options_to_args(options)
|
237
|
-
|
238
|
-
using_temp(target) do |tmpname|
|
239
|
-
result = Libis::Format::Tool::PdfTool.run('select', source, tmpname, *args)
|
240
|
-
unless result[:err].empty?
|
241
|
-
error("Pdf select encountered errors:\n%s", result[:err].join(join("\n")))
|
242
|
-
return nil
|
243
|
-
end
|
244
|
-
tmpname
|
245
|
-
end
|
246
99
|
end
|
247
100
|
|
248
101
|
def pdf_to_pdfa(source, target)
|
102
|
+
|
249
103
|
using_temp(target) do |tmpname|
|
250
104
|
result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
return nil
|
105
|
+
if result[:status] != 0
|
106
|
+
error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
|
107
|
+
next nil
|
255
108
|
else
|
256
|
-
|
257
|
-
if r[:status] != 0
|
258
|
-
error "Pdf/A file failed to validate with following errors:\n%s", (r[:err] || r[:out] || []).join("\n")
|
259
|
-
return nil
|
260
|
-
end
|
109
|
+
warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
|
261
110
|
end
|
262
111
|
tmpname
|
263
112
|
end
|
113
|
+
|
264
114
|
end
|
115
|
+
|
265
116
|
end
|
117
|
+
|
266
118
|
end
|
267
119
|
end
|
268
120
|
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
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'
|
9
|
+
|
10
|
+
module Libis
|
11
|
+
module Format
|
12
|
+
module Converter
|
13
|
+
|
14
|
+
class PdfOptimizer < 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]
|
23
|
+
end
|
24
|
+
|
25
|
+
def pdf_optimize(_)
|
26
|
+
#force usage of this converter
|
27
|
+
end
|
28
|
+
|
29
|
+
# Optimize the PDF
|
30
|
+
#
|
31
|
+
# This reduces the graphics quality to a level in order to limit file size. This option relies on the
|
32
|
+
# presence of ghostscript and takes one argument: the quality level. It should be one of:
|
33
|
+
#
|
34
|
+
# - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
|
35
|
+
# - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
|
36
|
+
# - 2 : good quality
|
37
|
+
# - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
|
38
|
+
# - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
|
39
|
+
#
|
40
|
+
# Note that the optimization is intended to be used with PDF's containing high-resolution images.
|
41
|
+
#
|
42
|
+
# @param [Integer] setting quality setting. [0-4]
|
43
|
+
def quality(setting = 1)
|
44
|
+
@quality = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert(source, target, format, opts = {})
|
48
|
+
super
|
49
|
+
|
50
|
+
optimize_pdf(source, target, @quality || 'ebook')
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
def optimize_pdf(source, target, quality)
|
55
|
+
|
56
|
+
using_temp(target) do |tmpname|
|
57
|
+
result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
|
58
|
+
unless result[:status] == 0
|
59
|
+
error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
|
60
|
+
next nil
|
61
|
+
end
|
62
|
+
tmpname
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/tool/pdf_split'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Format
|
9
|
+
module Converter
|
10
|
+
|
11
|
+
# noinspection DuplicatedCode
|
12
|
+
class PdfSplitter < 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_split(_)
|
24
|
+
#force usage of this converter
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.category
|
28
|
+
:splitter
|
29
|
+
end
|
30
|
+
|
31
|
+
# Split at given page. If omitted or nil, the source PDF will be split at every page
|
32
|
+
def page(v)
|
33
|
+
@page = v unless v.blank
|
34
|
+
end
|
35
|
+
|
36
|
+
def convert(source, target, format, opts = {})
|
37
|
+
super
|
38
|
+
|
39
|
+
result = split(source, target)
|
40
|
+
return nil unless result
|
41
|
+
|
42
|
+
result
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def split(source, target)
|
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
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
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'
|
9
|
+
|
10
|
+
module Libis
|
11
|
+
module Format
|
12
|
+
module Converter
|
13
|
+
|
14
|
+
class PdfWatermarker < 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]
|
23
|
+
end
|
24
|
+
|
25
|
+
def pdf_watermark(_)
|
26
|
+
#force usage of this converter
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize
|
30
|
+
super
|
31
|
+
@options[:text] = '© LIBIS'
|
32
|
+
@options[:opacity] = '0.3'
|
33
|
+
end
|
34
|
+
|
35
|
+
def file(v)
|
36
|
+
@options[:file] = v.blank? ? nil : v
|
37
|
+
end
|
38
|
+
|
39
|
+
def text(v)
|
40
|
+
@options[:text] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
def rotation(v)
|
44
|
+
@options[:rotation] = v unless v.blank?
|
45
|
+
end
|
46
|
+
|
47
|
+
def size(v)
|
48
|
+
@options[:size] = v unless v.blank?
|
49
|
+
end
|
50
|
+
|
51
|
+
def opacity(v)
|
52
|
+
@options[:opacity] = v unless v.blank?
|
53
|
+
end
|
54
|
+
|
55
|
+
def gap_size(v)
|
56
|
+
@options[:gap_size] = v
|
57
|
+
end
|
58
|
+
|
59
|
+
def gap_ratio(v)
|
60
|
+
@options[:gap_ratio] = v
|
61
|
+
end
|
62
|
+
|
63
|
+
def convert(source, target, format, opts = {})
|
64
|
+
super
|
65
|
+
|
66
|
+
result = convert_pdf(source, target)
|
67
|
+
return nil unless result
|
68
|
+
|
69
|
+
result
|
70
|
+
|
71
|
+
end
|
72
|
+
|
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
|
+
# noinspection DuplicatedCode
|
83
|
+
def convert_pdf(source, target)
|
84
|
+
|
85
|
+
using_temp(target) do |tmpname|
|
86
|
+
result = Libis::Format::Tool::PdfCopy.run(
|
87
|
+
source, tmpname,
|
88
|
+
@options.map {|k, v|
|
89
|
+
if v.nil?
|
90
|
+
nil
|
91
|
+
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
|
96
|
+
)
|
97
|
+
unless result[:err].empty?
|
98
|
+
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
99
|
+
next nil
|
100
|
+
end
|
101
|
+
tmpname
|
102
|
+
end
|
103
|
+
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# coding: utf-8
|
2
2
|
|
3
|
+
require 'set'
|
3
4
|
require 'singleton'
|
4
5
|
|
5
6
|
require 'libis/tools/logger'
|
@@ -10,6 +11,7 @@ require_relative 'chain'
|
|
10
11
|
module Libis
|
11
12
|
module Format
|
12
13
|
module Converter
|
14
|
+
|
13
15
|
class Repository
|
14
16
|
include Singleton
|
15
17
|
include ::Libis::Tools::Logger
|
@@ -22,15 +24,15 @@ module Libis
|
|
22
24
|
@converters_glob = File.join(File.dirname(__FILE__), '*_converter.rb')
|
23
25
|
end
|
24
26
|
|
25
|
-
def
|
27
|
+
def Repository.register(converter_class)
|
26
28
|
instance.converters.add? converter_class
|
27
29
|
end
|
28
30
|
|
29
|
-
def
|
31
|
+
def Repository.get_converters
|
30
32
|
instance.get_converters
|
31
33
|
end
|
32
34
|
|
33
|
-
def get_converters
|
35
|
+
def get_converters
|
34
36
|
if converters.empty?
|
35
37
|
Dir.glob(converters_glob).each do |filename|
|
36
38
|
# noinspection RubyResolve
|
@@ -40,12 +42,12 @@ module Libis
|
|
40
42
|
converters
|
41
43
|
end
|
42
44
|
|
43
|
-
def
|
45
|
+
def Repository.get_converter_chain(src_type, tgt_type, operations = {})
|
44
46
|
instance.get_converter_chain src_type, tgt_type, operations
|
45
47
|
end
|
46
48
|
|
47
49
|
def get_converter_chain(src_type, tgt_type, operations = {})
|
48
|
-
msg = "conversion from #{src_type} to #{tgt_type}"
|
50
|
+
msg = "conversion from #{src_type.to_s} to #{tgt_type.to_s}"
|
49
51
|
chain_list = find_chains src_type, tgt_type, operations
|
50
52
|
# if chain_list.length > 1
|
51
53
|
# warn "Found more than one conversion chain for #{msg}. Picking the first one."
|
@@ -68,6 +70,7 @@ module Libis
|
|
68
70
|
end
|
69
71
|
|
70
72
|
def build_chains(chain)
|
73
|
+
|
71
74
|
found = []
|
72
75
|
chains = [chain]
|
73
76
|
|
@@ -78,15 +81,18 @@ module Libis
|
|
78
81
|
new_chains += chains.map { |c| c.append(converter) }.flatten
|
79
82
|
end
|
80
83
|
|
81
|
-
found = new_chains.select
|
84
|
+
found = new_chains.select { |c| c.valid?}
|
82
85
|
return found unless found.empty?
|
83
86
|
|
84
87
|
chains = new_chains
|
85
88
|
end
|
86
89
|
|
87
90
|
found
|
91
|
+
|
88
92
|
end
|
93
|
+
|
89
94
|
end
|
95
|
+
|
90
96
|
end
|
91
97
|
end
|
92
98
|
end
|
@@ -1,38 +1,44 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
4
|
|
5
5
|
require 'libis/format/tool/spreadsheet_to_ods'
|
6
|
-
require 'libis/format/
|
6
|
+
require 'libis/format/library'
|
7
7
|
|
8
8
|
module Libis
|
9
9
|
module Format
|
10
10
|
module Converter
|
11
|
+
|
11
12
|
class SpreadsheetConverter < Libis::Format::Converter::Base
|
13
|
+
|
12
14
|
def self.input_types
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
[
|
16
|
+
:MSXLS,
|
17
|
+
:MSXLSX,
|
18
|
+
:OO_CALC
|
17
19
|
]
|
18
20
|
end
|
19
21
|
|
20
22
|
def self.output_types(format = nil)
|
21
|
-
return [] unless input_types.include?(format)
|
22
|
-
|
23
|
+
return [] unless input_types.include?(format) if format
|
23
24
|
[:OO_CALC]
|
24
25
|
end
|
25
26
|
|
26
27
|
def spreadsheet_convert(_)
|
27
|
-
#
|
28
|
+
#force usage of this converter
|
28
29
|
end
|
29
30
|
|
30
31
|
def convert(source, target, format, opts = {})
|
31
32
|
super
|
32
33
|
|
33
|
-
Format::Tool::SpreadsheetToOds.run(source, target)
|
34
|
+
return nil unless Format::Tool::SpreadsheetToOds.run(source, target)
|
35
|
+
|
36
|
+
target
|
37
|
+
|
34
38
|
end
|
39
|
+
|
35
40
|
end
|
41
|
+
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|