libis-format 1.0.8 → 1.2.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/.gitignore +1 -0
- data/Gemfile +2 -0
- data/data/AdobeRGB1998.icc +0 -0
- data/data/PDFA_def.ps +3 -3
- data/lib/libis/format/config.rb +1 -1
- data/lib/libis/format/converter/audio_converter.rb +6 -8
- data/lib/libis/format/converter/chain.rb +16 -4
- data/lib/libis/format/converter/email_converter.rb +2 -4
- data/lib/libis/format/converter/fop_pdf_converter.rb +0 -2
- data/lib/libis/format/converter/image_converter.rb +5 -3
- data/lib/libis/format/converter/jp2_converter.rb +3 -3
- data/lib/libis/format/converter/office_converter.rb +1 -3
- data/lib/libis/format/converter/pdf_converter.rb +13 -4
- data/lib/libis/format/converter/spreadsheet_converter.rb +1 -3
- data/lib/libis/format/converter/video_converter.rb +5 -2
- data/lib/libis/format/converter/xslt_converter.rb +15 -14
- data/lib/libis/format/tool/email_to_pdf.rb +52 -17
- data/lib/libis/format/tool/{ffmpeg.rb → ff_mpeg.rb} +10 -1
- data/lib/libis/format/tool/fop_pdf.rb +12 -0
- data/lib/libis/format/tool/office_to_pdf.rb +10 -1
- data/lib/libis/format/tool/pdf_copy.rb +11 -1
- data/lib/libis/format/tool/pdf_merge.rb +11 -1
- data/lib/libis/format/tool/pdf_optimizer.rb +11 -2
- data/lib/libis/format/tool/pdf_split.rb +11 -1
- data/lib/libis/format/tool/pdf_to_pdfa.rb +59 -43
- data/lib/libis/format/tool/pdfa_validator.rb +28 -35
- data/lib/libis/format/tool/spreadsheet_to_ods.rb +10 -1
- data/lib/libis/format/tool.rb +1 -1
- data/lib/libis/format/version.rb +1 -1
- data/libis-format.gemspec +2 -0
- data/tools/emailconverter.jar +0 -0
- data/tools/pdf2pdfa +395 -0
- metadata +20 -4
- data/data/eciRGB_v2.icc +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c8f2304a5f189140ad867cb1d7d9d41f280f796992c84514316b7e584628a64b
|
4
|
+
data.tar.gz: ee097826d8e73fa7fa72167b4a3eaebef5992bba8fd78a6e0d454fe552730d6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9fdb85d3847ba3ed08c96cc409b5e7f2c471d80edf61ab6581b28cb46380e1b48e8c65daf182717dd35cf216d91e50f1680d31a352d9aab557d54f7f3af61dc8
|
7
|
+
data.tar.gz: 0d8d4f7c29c0fa5da26a85eb82554796cb1ac18f98e00e3f1e700bd4eb79f647b8311f56e2eb7a46cc1679a2809fc140b1cc702856da1baacafd5127a65ea66f
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
Binary file
|
data/data/PDFA_def.ps
CHANGED
@@ -5,10 +5,10 @@
|
|
5
5
|
% unless the user modifies the corresponding line below.
|
6
6
|
|
7
7
|
% Define entries in the document Info dictionary :
|
8
|
-
/ICCProfile ([**
|
8
|
+
/ICCProfile ([**ICC profile**])
|
9
9
|
def
|
10
10
|
|
11
|
-
[
|
11
|
+
[ [**METADATA**]
|
12
12
|
/DOCINFO pdfmark
|
13
13
|
|
14
14
|
% Define an ICC profile :
|
@@ -35,6 +35,6 @@ def
|
|
35
35
|
/Type /OutputIntent % Must be so (the standard requires).
|
36
36
|
/S /GTS_PDFA1 % Must be so (the standard requires).
|
37
37
|
/DestOutputProfile {icc_PDFA} % Must be so (see above).
|
38
|
-
/OutputConditionIdentifier ([**
|
38
|
+
/OutputConditionIdentifier ([**ICC reference**])
|
39
39
|
>> /PUT pdfmark
|
40
40
|
[{Catalog} <</OutputIntents [ {OutputIntent_PDFA} ]>> /PUT pdfmark
|
data/lib/libis/format/config.rb
CHANGED
@@ -12,7 +12,6 @@ module Libis
|
|
12
12
|
Config[:java_cmd] = 'java'
|
13
13
|
Config[:j2k_cmd] = 'j2kdriver'
|
14
14
|
Config[:soffice_cmd] = 'soffice'
|
15
|
-
Config[:emai2pdf_cmd] = 'convert_email'
|
16
15
|
Config[:ghostscript_cmd] = 'gs'
|
17
16
|
Config[:droid_cmd] = '/opt/droid/droid.sh'
|
18
17
|
Config[:droid_temp_path] = '/tmp'
|
@@ -22,6 +21,7 @@ module Libis
|
|
22
21
|
Config[:fido_formats] = [(File.join(Libis::Format::DATA_DIR, 'lias_formats.xml'))]
|
23
22
|
Config[:pdf_tool] = File.join(Libis::Format::TOOL_DIR, 'PdfTool.jar')
|
24
23
|
Config[:preflight_jar] = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-2.0.13.jar')
|
24
|
+
Config[:email2pdf_jar] = File.join(Libis::Format::TOOL_DIR, 'emailconverter.jar')
|
25
25
|
# noinspection RubyStringKeysInHashInspection
|
26
26
|
Config[:xml_validations] = [['archive/ead', File.join(Libis::Format::DATA_DIR, 'ead.xsd')]]
|
27
27
|
Config[:type_database] = File.join(Libis::Format::DATA_DIR, 'types.yml')
|
@@ -97,19 +97,18 @@ module Libis
|
|
97
97
|
|
98
98
|
end
|
99
99
|
|
100
|
-
target
|
101
|
-
|
102
100
|
end
|
103
101
|
|
104
102
|
def assemble_and_convert(sources, target)
|
103
|
+
result = {}
|
105
104
|
Tempfile.create(%w(list .txt)) do |f|
|
106
105
|
sources.each {|src| f.puts src}
|
107
106
|
opts[:global] ||= []
|
108
107
|
opts[:global] += %w(-f concat)
|
109
108
|
f.close
|
110
|
-
|
109
|
+
result = convert_file(f.to_path, target)
|
111
110
|
end
|
112
|
-
|
111
|
+
result
|
113
112
|
end
|
114
113
|
|
115
114
|
def self.sounds_like(file1, file2, threshold, rate, channels)
|
@@ -155,6 +154,7 @@ module Libis
|
|
155
154
|
|
156
155
|
def convert_file(source, target)
|
157
156
|
opts = {global: [], input: [], filter: [], output: []}
|
157
|
+
|
158
158
|
opts[:global] << '-hide_banner'
|
159
159
|
opts[:global] << '-loglevel' << (@options[:quiet] ? 'fatal' : 'warning')
|
160
160
|
opts[:output] << '-vn' # disable input video stream in case it exists
|
@@ -168,10 +168,8 @@ module Libis
|
|
168
168
|
opts[:output] << '-ar' << @options[:sampling_freq] if @options[:sampling_freq]
|
169
169
|
opts[:output] << '-ac' << @options[:channels] if @options[:channels]
|
170
170
|
opts[:output] << '-f' << @options[:format] if @options[:format]
|
171
|
-
|
172
|
-
|
173
|
-
result
|
174
|
-
target
|
171
|
+
|
172
|
+
Libis::Format::Tool::FFMpeg.run(source, target, opts)
|
175
173
|
end
|
176
174
|
|
177
175
|
end
|
@@ -68,14 +68,18 @@ module Libis
|
|
68
68
|
end
|
69
69
|
|
70
70
|
temp_files = []
|
71
|
+
xtra_files = []
|
72
|
+
|
73
|
+
result = { commands: [] }
|
71
74
|
|
72
75
|
# noinspection RubyParenthesesAroundConditionInspection
|
73
|
-
|
76
|
+
conversion_success = converter_chain.each_with_index do |node, i|
|
74
77
|
|
75
78
|
target_type = node[:output]
|
76
79
|
converter_class = node[:converter]
|
77
80
|
converter = converter_class.new
|
78
81
|
|
82
|
+
|
79
83
|
node[:operations].each do |operation|
|
80
84
|
converter.send operation[:method], operation[:argument]
|
81
85
|
end if node[:operations]
|
@@ -90,17 +94,25 @@ module Libis
|
|
90
94
|
|
91
95
|
FileUtils.mkdir_p File.dirname(target)
|
92
96
|
|
93
|
-
|
97
|
+
r = converter.convert(src_file, target, target_type)
|
98
|
+
|
99
|
+
src_file = r[:files].first
|
100
|
+
xtra_files += r[:files][1..]
|
101
|
+
break :failed unless src_file1
|
94
102
|
|
95
|
-
|
103
|
+
result[:commands] << r.merge(converter: converter_class.name)
|
104
|
+
|
105
|
+
:success
|
96
106
|
|
97
107
|
end
|
98
108
|
|
109
|
+
result[:files] = [src_file] + xtra_files
|
110
|
+
|
99
111
|
temp_files.each do |f|
|
100
112
|
FileUtils.rm(f, force: true)
|
101
113
|
end
|
102
114
|
|
103
|
-
|
115
|
+
conversion_success == :failed ? nil : result
|
104
116
|
|
105
117
|
end
|
106
118
|
|
@@ -4,6 +4,7 @@ require_relative 'base'
|
|
4
4
|
|
5
5
|
require 'libis/format/tool/email_to_pdf'
|
6
6
|
require 'libis/format/type_database'
|
7
|
+
require 'rexml/document'
|
7
8
|
|
8
9
|
module Libis
|
9
10
|
module Format
|
@@ -27,10 +28,7 @@ module Libis
|
|
27
28
|
def convert(source, target, format, opts = {})
|
28
29
|
super
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
target
|
33
|
-
|
31
|
+
Format::Tool::EmailToPdf.run(source, target)
|
34
32
|
end
|
35
33
|
|
36
34
|
end
|
@@ -90,16 +90,16 @@ module Libis
|
|
90
90
|
end
|
91
91
|
|
92
92
|
|
93
|
-
Libis::Tools::Command.run(
|
93
|
+
result = Libis::Tools::Command.run(
|
94
94
|
Libis::Format::Config[:j2k_cmd],
|
95
95
|
'--input-file-name', source,
|
96
96
|
'--set-output-type', 'JP2',
|
97
97
|
*options,
|
98
98
|
'--output-file-name', target,
|
99
|
-
|
100
99
|
)
|
101
100
|
|
102
|
-
target
|
101
|
+
result.merge(files: [target], converter: self.class.name)
|
102
|
+
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
@@ -5,6 +5,7 @@ require_relative 'base'
|
|
5
5
|
require 'libis/tools/extend/hash'
|
6
6
|
require 'libis/format/tool/pdf_copy'
|
7
7
|
require 'libis/format/tool/pdf_to_pdfa'
|
8
|
+
require 'libis/format/tool/pdfa_validator'
|
8
9
|
require 'libis/format/tool/pdf_optimizer'
|
9
10
|
|
10
11
|
module Libis
|
@@ -119,7 +120,10 @@ module Libis
|
|
119
120
|
result = pdf_to_pdfa(source, target)
|
120
121
|
end
|
121
122
|
|
122
|
-
|
123
|
+
{
|
124
|
+
files: [result],
|
125
|
+
converter: self.class.name
|
126
|
+
}
|
123
127
|
|
124
128
|
end
|
125
129
|
|
@@ -160,11 +164,16 @@ module Libis
|
|
160
164
|
|
161
165
|
using_temp(target) do |tmpname|
|
162
166
|
result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
|
163
|
-
|
164
|
-
|
167
|
+
|
168
|
+
if result[:command][:status] != 0
|
169
|
+
error("Pdf/A conversion encountered errors:\n%s", (result[:command][:out] + result[:command][:err]).join("\n"))
|
165
170
|
next nil
|
166
171
|
else
|
167
|
-
|
172
|
+
r = Libis::Format::Tool::PdfaValidator.run tmpname
|
173
|
+
if r[:status] != 0
|
174
|
+
error "Pdf/A file failed to validate with following errors:\n%s", (r[:err] || r[:out] || []).join("\n")
|
175
|
+
next nil
|
176
|
+
end
|
168
177
|
end
|
169
178
|
tmpname
|
170
179
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
require_relative 'base'
|
2
|
-
require 'libis/format/tool/
|
2
|
+
require 'libis/format/tool/ff_mpeg'
|
3
3
|
|
4
4
|
require 'fileutils'
|
5
5
|
|
@@ -179,7 +179,10 @@ module Libis
|
|
179
179
|
|
180
180
|
end
|
181
181
|
|
182
|
-
|
182
|
+
{
|
183
|
+
files: [target],
|
184
|
+
converter: self.class.name
|
185
|
+
}
|
183
186
|
|
184
187
|
end
|
185
188
|
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "base"
|
2
2
|
|
3
3
|
module Libis
|
4
4
|
module Format
|
5
5
|
module Converter
|
6
|
-
|
7
6
|
class XsltConverter < Libis::Format::Converter::Base
|
8
|
-
|
9
7
|
def self.input_types
|
10
8
|
[:XML]
|
11
9
|
end
|
12
10
|
|
13
11
|
def self.output_types(format = nil)
|
14
|
-
|
12
|
+
if format
|
13
|
+
return [] unless input_types.include?(format)
|
14
|
+
end
|
15
15
|
[:XML, :HTML, :TXT]
|
16
16
|
end
|
17
17
|
|
@@ -28,20 +28,20 @@ module Libis
|
|
28
28
|
end
|
29
29
|
|
30
30
|
unless @options[:xsl_file]
|
31
|
-
error
|
31
|
+
error "No xsl_file supplied"
|
32
32
|
return nil
|
33
33
|
end
|
34
34
|
|
35
35
|
FileUtils.mkpath(File.dirname(target))
|
36
36
|
|
37
37
|
if RUBY_PLATFORM == "java"
|
38
|
-
require
|
38
|
+
require "saxon-xslt"
|
39
39
|
xsl = Saxon.XSLT(File.open(@options[:xsl_file]))
|
40
40
|
xml = Saxon.XML(File.open(source))
|
41
41
|
result = xsl.transform(xml)
|
42
|
-
File.
|
42
|
+
File.write(target, result.to_s)
|
43
43
|
else
|
44
|
-
require
|
44
|
+
require "nokogiri"
|
45
45
|
|
46
46
|
doc = nil
|
47
47
|
begin
|
@@ -65,7 +65,7 @@ module Libis
|
|
65
65
|
xsl = nil
|
66
66
|
|
67
67
|
begin
|
68
|
-
fp = File.open(file,
|
68
|
+
fp = File.open(file, "r")
|
69
69
|
xsl = Nokogiri::XSLT(fp) do |config|
|
70
70
|
config.options = Nokogiri::XML::ParseOptions::STRICT | Nokogiri::XML::ParseOptions::NOBLANKS
|
71
71
|
end
|
@@ -80,7 +80,7 @@ module Libis
|
|
80
80
|
|
81
81
|
begin
|
82
82
|
target_xml = xsl.transform(doc)
|
83
|
-
fp = File.open(target,
|
83
|
+
fp = File.open(target, "w")
|
84
84
|
fp.write(target_xml)
|
85
85
|
rescue Exception => e
|
86
86
|
error "Error transforming '#{source}' with '#{file}': #{e.message} @ #{e.backtrace[0]}"
|
@@ -89,13 +89,14 @@ module Libis
|
|
89
89
|
fp.close unless fp.nil? or fp.closed?
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
92
|
+
{
|
93
|
+
command: {status: 0},
|
94
|
+
files: [target]
|
95
|
+
}
|
94
96
|
|
97
|
+
end
|
95
98
|
end
|
96
|
-
|
97
99
|
end
|
98
|
-
|
99
100
|
end
|
100
101
|
end
|
101
102
|
end
|
@@ -1,40 +1,75 @@
|
|
1
|
-
require
|
1
|
+
require "fileutils"
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
3
|
+
require "libis/tools/extend/string"
|
4
|
+
require "libis/tools/logger"
|
5
|
+
require "libis/tools/command"
|
6
6
|
|
7
|
-
require
|
7
|
+
require "libis/format/config"
|
8
|
+
require "rexml/document"
|
8
9
|
|
9
10
|
module Libis
|
10
11
|
module Format
|
11
12
|
module Tool
|
12
|
-
|
13
13
|
class EmailToPdf
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:email2pdf_cmd], "-v")
|
18
|
+
result[:status] == 0
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.run(source, target, options = {})
|
17
|
-
|
22
|
+
new.run source, target, options
|
18
23
|
end
|
19
24
|
|
20
25
|
def run(source, target, _ = {})
|
21
26
|
timeout = Libis::Format::Config[:timeouts][:email2pdf] || 120
|
22
27
|
result = Libis::Tools::Command.run(
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
Libis::Format::Config[:java_cmd],
|
29
|
+
"-Duser.timezone=Europe/Brussels", "-Duser.language=nl", "-Duser.country=BE",
|
30
|
+
"-jar", Libis::Format::Config[:email2pdf_jar],
|
31
|
+
"-e", "-hd", "-a",
|
32
|
+
"-o", target,
|
33
|
+
source,
|
34
|
+
timeout: timeout,
|
35
|
+
kill_after: timeout * 2
|
28
36
|
)
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
raise
|
38
|
+
warn "EmailToPdf conversion messages: \n\t#{result[:err].join("\n\t")}" unless result[:err].empty?
|
39
|
+
|
40
|
+
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
41
|
+
raise "#{self.class} failed to generate target file #{target}" unless File.exist?(target)
|
42
|
+
raise "#{self.class} command failed with status code #{result[:status]}" unless result[:status] == 0
|
43
|
+
|
44
|
+
base_path = File.join(File.dirname(target), File.basename(target, ".*"))
|
45
|
+
headers_file = "#{base_path}.headers.xml"
|
46
|
+
headers = read_header(headers_file)
|
33
47
|
|
34
|
-
|
48
|
+
{
|
49
|
+
command: result,
|
50
|
+
files: [target, headers_file] + headers[:attachments].map { |a| File.join("#{base_path}-attachments", a) },
|
51
|
+
headers: headers
|
52
|
+
}
|
35
53
|
end
|
36
|
-
end
|
37
54
|
|
55
|
+
private
|
56
|
+
|
57
|
+
def read_header(headers_file)
|
58
|
+
headers = {}
|
59
|
+
return headers unless File.exist?(headers_file)
|
60
|
+
doc = REXML::Document.new(File.new(headers_file))
|
61
|
+
root = doc.root
|
62
|
+
root.children.each do |element|
|
63
|
+
case element.name
|
64
|
+
when "attachments"
|
65
|
+
headers[:attachments] = element.elements.map { |e| e.text }
|
66
|
+
else
|
67
|
+
headers[element.name.to_sym] = element.text
|
68
|
+
end
|
69
|
+
end
|
70
|
+
headers
|
71
|
+
end
|
72
|
+
end
|
38
73
|
end
|
39
74
|
end
|
40
75
|
end
|
@@ -13,6 +13,11 @@ module Libis
|
|
13
13
|
include Singleton
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:ffmpeg_cmd], "-h")
|
18
|
+
result[:status] == 0
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.run(source, target, options = {})
|
17
22
|
self.instance.run source, target, options
|
18
23
|
end
|
@@ -38,7 +43,11 @@ module Libis
|
|
38
43
|
|
39
44
|
warn "FFMpeg warnings: #{(result[:err] + result[:out]).join("\n")}" unless result[:err].empty?
|
40
45
|
|
41
|
-
|
46
|
+
{
|
47
|
+
command: result,
|
48
|
+
files: [ target ]
|
49
|
+
}
|
50
|
+
|
42
51
|
end
|
43
52
|
|
44
53
|
end
|
@@ -13,6 +13,12 @@ module Libis
|
|
13
13
|
class FopPdf
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
|
18
|
+
return false unless result[:status] == 0
|
19
|
+
File.exist?(Libis::Format::Config[:fop_jar])
|
20
|
+
end
|
21
|
+
|
16
22
|
def self.run(xml, target, options = [])
|
17
23
|
self.new.run xml, target, options
|
18
24
|
end
|
@@ -27,6 +33,7 @@ module Libis
|
|
27
33
|
result = Libis::Tools::Command.run(
|
28
34
|
Libis::Format::Config[:java_cmd],
|
29
35
|
"-Dfop.home=#{File.dirname(Libis::Format::Config[:fop_jar])}",
|
36
|
+
'-Djava.awt.headless=true',
|
30
37
|
'-jar', Libis::Format::Config[:fop_jar],
|
31
38
|
'-fo', xml,
|
32
39
|
'-pdf', target,
|
@@ -37,6 +44,11 @@ module Libis
|
|
37
44
|
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
38
45
|
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
39
46
|
|
47
|
+
{
|
48
|
+
command: result,
|
49
|
+
files: [ target ]
|
50
|
+
}
|
51
|
+
|
40
52
|
end
|
41
53
|
end
|
42
54
|
|
@@ -13,6 +13,11 @@ module Libis
|
|
13
13
|
class OfficeToPdf
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:soffice_cmd], "--version")
|
18
|
+
result[:status] == 0
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.run(source, target, options = {})
|
17
22
|
self.new.run source, target, options
|
18
23
|
end
|
@@ -47,10 +52,14 @@ module Libis
|
|
47
52
|
|
48
53
|
FileUtils.copy tgt_file, target, preserve: true
|
49
54
|
|
55
|
+
{
|
56
|
+
command: result,
|
57
|
+
files: [ target ]
|
58
|
+
}
|
59
|
+
|
50
60
|
ensure
|
51
61
|
FileUtils.rmtree workdir rescue nil
|
52
62
|
|
53
|
-
result[:out]
|
54
63
|
end
|
55
64
|
end
|
56
65
|
|
@@ -13,6 +13,12 @@ module Libis
|
|
13
13
|
class PdfCopy
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
|
18
|
+
return false unless result[:status] == 0
|
19
|
+
File.exist?(Libis::Format::Config[:pdf_tool])
|
20
|
+
end
|
21
|
+
|
16
22
|
def self.run(source, target, options = [])
|
17
23
|
self.new.run source, target, options
|
18
24
|
end
|
@@ -38,7 +44,11 @@ module Libis
|
|
38
44
|
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
39
45
|
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
40
46
|
|
41
|
-
|
47
|
+
{
|
48
|
+
command: result,
|
49
|
+
files: [ target ]
|
50
|
+
}
|
51
|
+
|
42
52
|
end
|
43
53
|
end
|
44
54
|
|
@@ -13,6 +13,12 @@ module Libis
|
|
13
13
|
class PdfMerge
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
|
18
|
+
return false unless result[:status] == 0
|
19
|
+
File.exist?(Libis::Format::Config[:pdf_tool])
|
20
|
+
end
|
21
|
+
|
16
22
|
def self.run(source, target, options = [])
|
17
23
|
self.new.run source, target, options
|
18
24
|
end
|
@@ -39,7 +45,11 @@ module Libis
|
|
39
45
|
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
40
46
|
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
41
47
|
|
42
|
-
|
48
|
+
{
|
49
|
+
command: result,
|
50
|
+
files: [ target ]
|
51
|
+
}
|
52
|
+
|
43
53
|
end
|
44
54
|
end
|
45
55
|
|
@@ -13,6 +13,11 @@ module Libis
|
|
13
13
|
class PdfOptimizer
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
|
+
def self.installed?
|
17
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:ghostscript_cmd], "--version")
|
18
|
+
result[:status] == 0
|
19
|
+
end
|
20
|
+
|
16
21
|
def self.run(source, target, quality)
|
17
22
|
self.new.run source, target, quality
|
18
23
|
end
|
@@ -21,7 +26,7 @@ module Libis
|
|
21
26
|
|
22
27
|
timeout = Libis::Format::Config[:timeouts][:pdf_optimizer]
|
23
28
|
result = Libis::Tools::Command.run(
|
24
|
-
|
29
|
+
Libis::Format::Config[:ghostscript_cmd],
|
25
30
|
'-sDEVICE=pdfwrite',
|
26
31
|
'-dCompatibilityLevel=1.4',
|
27
32
|
"-dPDFSETTINGS=/#{quality}",
|
@@ -36,7 +41,11 @@ module Libis
|
|
36
41
|
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
37
42
|
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
38
43
|
|
39
|
-
|
44
|
+
{
|
45
|
+
command: result,
|
46
|
+
files: [ target ]
|
47
|
+
}
|
48
|
+
|
40
49
|
end
|
41
50
|
end
|
42
51
|
|