libis-format 1.2.9 → 1.3.2
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/Gemfile +4 -0
- data/bin/{pdf_copy → pdf_tool} +3 -2
- data/data/types.yml +1 -1
- data/lib/libis/format/command_line.rb +2 -3
- data/lib/libis/format/config.rb +17 -20
- data/lib/libis/format/converter/base.rb +9 -16
- data/lib/libis/format/converter/chain.rb +36 -28
- data/lib/libis/format/converter/email_converter.rb +5 -8
- data/lib/libis/format/converter/fop_pdf_converter.rb +4 -6
- data/lib/libis/format/converter/image_converter.rb +51 -58
- data/lib/libis/format/converter/jp2_converter.rb +33 -35
- data/lib/libis/format/converter/office_converter.rb +19 -23
- data/lib/libis/format/converter/pdf_converter.rb +133 -52
- data/lib/libis/format/converter/repository.rb +7 -13
- data/lib/libis/format/converter/spreadsheet_converter.rb +7 -11
- data/lib/libis/format/converter/video_converter.rb +41 -55
- data/lib/libis/format/converter/xslt_converter.rb +14 -13
- data/lib/libis/format/converter.rb +1 -1
- data/lib/libis/format/identifier.rb +41 -43
- data/lib/libis/format/tool/droid.rb +29 -30
- data/lib/libis/format/tool/ff_mpeg.rb +11 -13
- data/lib/libis/format/tool/fido.rb +1 -1
- data/lib/libis/format/tool/pdf_optimizer.rb +21 -27
- data/lib/libis/format/tool/pdf_to_pdfa.rb +2 -6
- data/lib/libis/format/tool/pdf_tool.rb +52 -0
- data/lib/libis/format/tool/pdfa_validator.rb +2 -3
- data/lib/libis/format/tool/spreadsheet_to_ods.rb +23 -20
- data/lib/libis/format/tool.rb +2 -2
- data/lib/libis/format/type_database.rb +51 -28
- data/lib/libis/format/type_database_impl.rb +57 -24
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format.rb +3 -2
- data/lib/libis-format.rb +2 -0
- data/tools/PdfTool.jar +0 -0
- data/tools/pdfbox/pdfbox-app-3.0.3.jar +0 -0
- data/tools/pdfbox/{preflight-app-2.0.13.jar → preflight-app-3.0.3.jar} +0 -0
- metadata +8 -10
- data/lib/libis/format/tool/pdf_copy.rb +0 -57
- data/lib/libis/format/tool/pdf_merge.rb +0 -58
- data/lib/libis/format/tool/pdf_split.rb +0 -56
- data/tools/pdfbox/pdfbox-app-2.0.13.jar +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'fileutils'
|
2
4
|
|
3
5
|
require 'libis/tools/extend/string'
|
@@ -9,61 +11,62 @@ require 'libis/format/config'
|
|
9
11
|
module Libis
|
10
12
|
module Format
|
11
13
|
module Tool
|
12
|
-
|
13
14
|
class SpreadsheetToOds
|
14
15
|
include ::Libis::Tools::Logger
|
15
16
|
|
16
17
|
def self.installed?
|
17
|
-
result = Libis::Tools::Command.run(Libis::Format::Config[:soffice_cmd],
|
18
|
-
result
|
18
|
+
result = Libis::Tools::Command.run(Libis::Format::Config[:soffice_cmd], '--version')
|
19
|
+
result.zero?
|
19
20
|
end
|
20
21
|
|
21
22
|
def self.run(source, target, options = {})
|
22
|
-
|
23
|
+
new.run source, target, options
|
23
24
|
end
|
24
25
|
|
25
26
|
def run(source, target, options = {})
|
26
27
|
workdir = '/...'
|
27
28
|
workdir = Dir.tmpdir unless Dir.exist? workdir
|
28
29
|
|
29
|
-
workdir = File.join(workdir, rand(
|
30
|
+
workdir = File.join(workdir, rand(1_000_000).to_s)
|
30
31
|
FileUtils.mkpath(workdir)
|
31
32
|
|
32
33
|
src_file = File.join(workdir, File.basename(source))
|
33
34
|
FileUtils.symlink source, src_file
|
34
35
|
|
35
|
-
tgt_file = File.join(workdir, File.basename(source, '.*')
|
36
|
+
tgt_file = File.join(workdir, "#{File.basename(source, '.*')}.ods")
|
36
37
|
|
37
38
|
export_filter = options[:export_filter] || 'ods'
|
38
39
|
|
39
40
|
timeout = Libis::Format::Config[:timeouts][:spreadsheet_to_ods] ||
|
40
|
-
|
41
|
+
Libis::Format::Config[:timeouts][:office_to_pdf]
|
41
42
|
result = Libis::Tools::Command.run(
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
Libis::Format::Config[:soffice_cmd], '--headless',
|
44
|
+
"-env:UserInstallation=file://#{workdir}",
|
45
|
+
'--convert-to', export_filter,
|
46
|
+
'--outdir', workdir, src_file,
|
47
|
+
timeout:,
|
48
|
+
kill_after: timeout * 2
|
48
49
|
)
|
49
50
|
|
50
|
-
raise
|
51
|
+
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
52
|
+
|
51
53
|
warn "OfficeToPdf conversion messages: \n\t#{result[:err].join("\n\t")}" unless result[:err].empty?
|
52
|
-
raise
|
54
|
+
raise "#{self.class} failed to generate target file #{tgt_file}" unless File.exist?(tgt_file)
|
53
55
|
|
54
56
|
FileUtils.copy tgt_file, target, preserve: true
|
55
57
|
|
56
58
|
{
|
57
59
|
command: result,
|
58
|
-
files: [
|
60
|
+
files: [target]
|
59
61
|
}
|
60
|
-
|
61
62
|
ensure
|
62
|
-
|
63
|
-
|
63
|
+
begin
|
64
|
+
FileUtils.rmtree workdir
|
65
|
+
rescue StandardError
|
66
|
+
nil
|
67
|
+
end
|
64
68
|
end
|
65
69
|
end
|
66
|
-
|
67
70
|
end
|
68
71
|
end
|
69
72
|
end
|
data/lib/libis/format/tool.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# code utf-8
|
2
4
|
|
3
5
|
module Libis
|
4
6
|
module Format
|
5
7
|
module Tool
|
6
|
-
|
7
8
|
autoload :Droid, 'libis/format/tool/droid'
|
8
9
|
autoload :ExtensionIdentification, 'libis/format/tool/extension_identification'
|
9
10
|
autoload :Fido, 'libis/format/tool/fido'
|
@@ -19,7 +20,6 @@ module Libis
|
|
19
20
|
autoload :PdfToPdfa, 'libis/format/tool/pdf_to_pdfa'
|
20
21
|
autoload :PdfaValidator, 'libis/format/tool/pdfa_validator'
|
21
22
|
autoload :MsgToPdf, 'libis/format/tool/msg_to_pdf'
|
22
|
-
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,11 +1,10 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
require 'libis/tools/extend/hash'
|
5
5
|
|
6
6
|
module Libis
|
7
7
|
module Format
|
8
|
-
|
9
8
|
# noinspection RubyClassVariableUsageInspection
|
10
9
|
class TypeDatabase
|
11
10
|
@implementation = Libis::Format::TypeDatabaseImpl.instance
|
@@ -16,16 +15,25 @@ module Libis
|
|
16
15
|
|
17
16
|
def self.enrich(info, map_keys = {})
|
18
17
|
return {} unless info.is_a? Hash
|
19
|
-
|
18
|
+
|
19
|
+
mapper = Hash.new { |hash, key| hash[key] = key }
|
20
20
|
mapper.merge! map_keys
|
21
21
|
unless (puid = info[mapper[:PUID]]).blank?
|
22
|
-
info[mapper[:TYPE]] ||=
|
22
|
+
info[mapper[:TYPE]] ||= begin
|
23
|
+
puid_infos(puid).first[:TYPE]
|
24
|
+
rescue StandardError
|
25
|
+
nil
|
26
|
+
end
|
23
27
|
end
|
24
28
|
unless (mime = info[mapper[:MIME]]).blank?
|
25
|
-
info[mapper[:TYPE]] ||=
|
29
|
+
info[mapper[:TYPE]] ||= begin
|
30
|
+
mime_infos(mime).first[:TYPE]
|
31
|
+
rescue StandardError
|
32
|
+
nil
|
33
|
+
end
|
26
34
|
end
|
27
35
|
unless (type_name = info[mapper[:TYPE]]).nil?
|
28
|
-
mapper.
|
36
|
+
mapper.each_key do |key|
|
29
37
|
info[mapper[key]] = get(type_name, key) || info[mapper[key]]
|
30
38
|
end
|
31
39
|
info[mapper[:GROUP]] = type_group(type_name)
|
@@ -35,13 +43,22 @@ module Libis
|
|
35
43
|
|
36
44
|
def self.normalize(info, map_keys = {})
|
37
45
|
return {} unless info.is_a? Hash
|
38
|
-
|
46
|
+
|
47
|
+
mapper = Hash.new { |hash, key| hash[key] = key }
|
39
48
|
mapper.merge! map_keys
|
40
49
|
unless (puid = info[mapper[:PUID]]).blank?
|
41
|
-
info[mapper[:TYPE]] ||=
|
50
|
+
info[mapper[:TYPE]] ||= begin
|
51
|
+
puid_infos(puid).first[:TYPE]
|
52
|
+
rescue StandardError
|
53
|
+
nil
|
54
|
+
end
|
42
55
|
end
|
43
56
|
unless (mime = info[mapper[:MIME]]).blank?
|
44
|
-
info[mapper[:TYPE]] ||=
|
57
|
+
info[mapper[:TYPE]] ||= begin
|
58
|
+
mime_infos(mime).first[:TYPE]
|
59
|
+
rescue StandardError
|
60
|
+
nil
|
61
|
+
end
|
45
62
|
end
|
46
63
|
unless (type_name = info[mapper[:TYPE]]).nil?
|
47
64
|
info[mapper[:MIME]] = type_mimetypes(type_name).first if type_mimetypes(type_name).first
|
@@ -52,35 +69,35 @@ module Libis
|
|
52
69
|
|
53
70
|
def self.get(type_name, key)
|
54
71
|
case key
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
72
|
+
when :MIME
|
73
|
+
type_mimetypes(type_name).first
|
74
|
+
when :PUID
|
75
|
+
type_puids(type_name).first
|
76
|
+
when :EXTENSION
|
77
|
+
type_extentions(type_name).first
|
78
|
+
else
|
79
|
+
typeinfo(type_name)[key]
|
63
80
|
end
|
64
81
|
end
|
65
82
|
|
66
|
-
def self.type_group(
|
67
|
-
typeinfo(
|
83
|
+
def self.type_group(ftype)
|
84
|
+
typeinfo(ftype)[:GROUP]
|
68
85
|
end
|
69
86
|
|
70
|
-
def self.type_mimetypes(
|
71
|
-
typeinfo(
|
87
|
+
def self.type_mimetypes(ftype)
|
88
|
+
typeinfo(ftype)[:MIME] || []
|
72
89
|
end
|
73
90
|
|
74
|
-
def self.type_puids(
|
75
|
-
typeinfo(
|
91
|
+
def self.type_puids(ftype)
|
92
|
+
typeinfo(ftype)[:PUID] || []
|
76
93
|
end
|
77
94
|
|
78
|
-
def self.type_extentions(
|
79
|
-
typeinfo(
|
95
|
+
def self.type_extentions(ftype)
|
96
|
+
typeinfo(ftype)[:EXTENSIONS] || []
|
80
97
|
end
|
81
98
|
|
82
|
-
def self.typeinfo(
|
83
|
-
@implementation.typeinfo(
|
99
|
+
def self.typeinfo(ftype)
|
100
|
+
@implementation.typeinfo(ftype)
|
84
101
|
end
|
85
102
|
|
86
103
|
def self.group_types(group)
|
@@ -127,7 +144,13 @@ module Libis
|
|
127
144
|
@implementation.known_mime?(mime)
|
128
145
|
end
|
129
146
|
|
130
|
-
|
147
|
+
def self.groups
|
148
|
+
@implementation.groups
|
149
|
+
end
|
131
150
|
|
151
|
+
def self.export_csv(filename, **options)
|
152
|
+
@implementation.export_csv(filename, **options)
|
153
|
+
end
|
154
|
+
end
|
132
155
|
end
|
133
156
|
end
|
@@ -1,21 +1,22 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'singleton'
|
4
4
|
require 'yaml'
|
5
|
+
require 'csv'
|
5
6
|
|
6
7
|
require 'libis/tools/logger'
|
7
8
|
require 'libis/tools/extend/hash'
|
8
9
|
require 'libis/tools/extend/string'
|
10
|
+
require 'libis/tools/extend/symbol'
|
9
11
|
|
10
12
|
module Libis
|
11
13
|
module Format
|
12
|
-
|
13
14
|
class TypeDatabaseImpl
|
14
15
|
include Singleton
|
15
16
|
include ::Libis::Tools::Logger
|
16
17
|
|
17
|
-
def typeinfo(
|
18
|
-
@types[
|
18
|
+
def typeinfo(ftype)
|
19
|
+
@types[ftype.to_sym] || {}
|
19
20
|
end
|
20
21
|
|
21
22
|
def group_types(group)
|
@@ -26,58 +27,84 @@ module Libis
|
|
26
27
|
|
27
28
|
def puid_infos(puid)
|
28
29
|
@types.select do |_, v|
|
29
|
-
v[:PUID].include? puid
|
30
|
+
v[:PUID].include? puid
|
31
|
+
rescue StandardError
|
32
|
+
false
|
30
33
|
end.values
|
31
34
|
end
|
32
35
|
|
33
36
|
def puid_types(puid)
|
34
37
|
@types.select do |_, v|
|
35
|
-
v[:PUID].include? puid
|
38
|
+
v[:PUID].include? puid
|
39
|
+
rescue StandardError
|
40
|
+
false
|
36
41
|
end.keys
|
37
42
|
end
|
38
43
|
|
39
44
|
def mime_infos(mime)
|
40
45
|
@types.select do |_, v|
|
41
|
-
v[:MIME].include? mime
|
46
|
+
v[:MIME].include? mime
|
47
|
+
rescue StandardError
|
48
|
+
false
|
42
49
|
end.values
|
43
50
|
end
|
44
51
|
|
45
52
|
def mime_types(mime)
|
46
53
|
@types.select do |_, v|
|
47
|
-
v[:MIME].include? mime
|
54
|
+
v[:MIME].include? mime
|
55
|
+
rescue StandardError
|
56
|
+
false
|
48
57
|
end.keys
|
49
58
|
end
|
50
59
|
|
51
60
|
def ext_infos(ext)
|
52
|
-
ext = ext.gsub
|
61
|
+
ext = ext.gsub(/^\./, '')
|
53
62
|
@types.select do |_, v|
|
54
|
-
v[:EXTENSIONS].include?(ext)
|
63
|
+
v[:EXTENSIONS].include?(ext)
|
64
|
+
rescue StandardError
|
65
|
+
false
|
55
66
|
end.values
|
56
67
|
end
|
57
68
|
|
58
69
|
def ext_types(ext)
|
59
|
-
ext = ext.gsub
|
70
|
+
ext = ext.gsub(/^\./, '')
|
60
71
|
@types.select do |_, v|
|
61
|
-
v[:EXTENSIONS].include?(ext)
|
72
|
+
v[:EXTENSIONS].include?(ext)
|
73
|
+
rescue StandardError
|
74
|
+
false
|
62
75
|
end.keys
|
63
76
|
end
|
64
77
|
|
65
78
|
def puid_typeinfo(puid)
|
66
79
|
@types.each do |_, v|
|
67
|
-
return v if v[:PUID]
|
80
|
+
return v if v[:PUID]&.include?(puid)
|
68
81
|
end
|
69
82
|
nil
|
70
83
|
end
|
71
84
|
|
72
85
|
def known_mime?(mime)
|
73
86
|
@types.each do |_, v|
|
74
|
-
return true if v[:MIME]
|
87
|
+
return true if v[:MIME]&.include? mime
|
75
88
|
end
|
76
89
|
false
|
77
90
|
end
|
78
91
|
|
92
|
+
def groups
|
93
|
+
@types.values.map(&:dig.with(:GROUP)).uniq
|
94
|
+
end
|
95
|
+
|
96
|
+
def export_csv(filename, **options)
|
97
|
+
headers = @types.values.each_with_object(Set.new) { |v, s| v.each_key { |k| s << k.to_s } }
|
98
|
+
options[:headers] = headers.to_a
|
99
|
+
CSV.open(filename, 'w', **options) do |csv|
|
100
|
+
@types.each_value do |v|
|
101
|
+
csv << CSV::Row.new(v.keys, v.values.map { |x| x.is_a?(Array) ? x.join(', ') : x })
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
79
106
|
def load_types(file_or_hash = {}, append = true)
|
80
|
-
hash = file_or_hash.is_a?(Hash) ? file_or_hash : YAML
|
107
|
+
hash = file_or_hash.is_a?(Hash) ? file_or_hash : YAML.load_file(file_or_hash)
|
81
108
|
# noinspection RubyResolve
|
82
109
|
hash.each do |group, type_info|
|
83
110
|
type_info.each do |type_name, info|
|
@@ -85,12 +112,20 @@ module Libis
|
|
85
112
|
info.symbolize_keys!
|
86
113
|
info[:TYPE] = type_key
|
87
114
|
info[:GROUP] = group.to_sym
|
88
|
-
info[:MIME] =
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
115
|
+
info[:MIME] = begin
|
116
|
+
info[:MIME].strip.split(/[\s,]+/).map(&:strip)
|
117
|
+
rescue StandardError
|
118
|
+
[]
|
119
|
+
end
|
120
|
+
info[:EXTENSIONS] = begin
|
121
|
+
info[:EXTENSIONS].strip.split(/[\s,]+/).map(&:strip)
|
122
|
+
rescue StandardError
|
123
|
+
[]
|
124
|
+
end
|
125
|
+
info[:PUID] = info[:PUID].strip.split(/[\s,]+/).map(&:strip) if info[:PUID]
|
126
|
+
if @types.key?(type_key)
|
127
|
+
warn 'Type %s already defined; merging with info from %s.', type_name, file_or_hash
|
128
|
+
info.merge!(@types[type_key]) do |_, v_new, v_old|
|
94
129
|
case v_old
|
95
130
|
when Array
|
96
131
|
append ? v_old + v_new : v_new + v_old
|
@@ -109,12 +144,10 @@ module Libis
|
|
109
144
|
protected
|
110
145
|
|
111
146
|
def initialize
|
112
|
-
@types =
|
147
|
+
@types = {}
|
113
148
|
type_database = Libis::Format::Config[:type_database]
|
114
149
|
load_types(type_database)
|
115
150
|
end
|
116
|
-
|
117
151
|
end
|
118
|
-
|
119
152
|
end
|
120
153
|
end
|
data/lib/libis/format/version.rb
CHANGED
data/lib/libis/format.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'libis/format/version'
|
2
4
|
|
3
5
|
module Libis
|
@@ -13,6 +15,5 @@ module Libis
|
|
13
15
|
ROOT_DIR = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
|
14
16
|
DATA_DIR = File.join(ROOT_DIR, 'data')
|
15
17
|
TOOL_DIR = File.join(ROOT_DIR, 'tools')
|
16
|
-
|
17
18
|
end
|
18
|
-
end
|
19
|
+
end
|
data/lib/libis-format.rb
CHANGED
data/tools/PdfTool.jar
CHANGED
Binary file
|
Binary file
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: libis-format
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
4
|
+
version: 1.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chromaprint
|
@@ -229,7 +229,7 @@ executables:
|
|
229
229
|
- fido_tool
|
230
230
|
- formatinfo
|
231
231
|
- libis_format
|
232
|
-
-
|
232
|
+
- pdf_tool
|
233
233
|
extensions: []
|
234
234
|
extra_rdoc_files: []
|
235
235
|
files:
|
@@ -240,7 +240,7 @@ files:
|
|
240
240
|
- bin/fido_tool
|
241
241
|
- bin/formatinfo
|
242
242
|
- bin/libis_format
|
243
|
-
- bin/
|
243
|
+
- bin/pdf_tool
|
244
244
|
- data/AdobeRGB1998.icc
|
245
245
|
- data/ISOcoated_v2_eci.icc
|
246
246
|
- data/PDFA_def.ps
|
@@ -281,11 +281,9 @@ files:
|
|
281
281
|
- lib/libis/format/tool/identification_tool.rb
|
282
282
|
- lib/libis/format/tool/msg_to_pdf.rb
|
283
283
|
- lib/libis/format/tool/office_to_pdf.rb
|
284
|
-
- lib/libis/format/tool/pdf_copy.rb
|
285
|
-
- lib/libis/format/tool/pdf_merge.rb
|
286
284
|
- lib/libis/format/tool/pdf_optimizer.rb
|
287
|
-
- lib/libis/format/tool/pdf_split.rb
|
288
285
|
- lib/libis/format/tool/pdf_to_pdfa.rb
|
286
|
+
- lib/libis/format/tool/pdf_tool.rb
|
289
287
|
- lib/libis/format/tool/pdfa_validator.rb
|
290
288
|
- lib/libis/format/tool/spreadsheet_to_ods.rb
|
291
289
|
- lib/libis/format/type_database.rb
|
@@ -346,8 +344,8 @@ files:
|
|
346
344
|
- tools/fop/lib/xmlgraphics-commons.LICENSE.txt
|
347
345
|
- tools/fop/lib/xmlgraphics-commons.NOTICE.txt
|
348
346
|
- tools/pdf2pdfa
|
349
|
-
- tools/pdfbox/pdfbox-app-
|
350
|
-
- tools/pdfbox/preflight-app-
|
347
|
+
- tools/pdfbox/pdfbox-app-3.0.3.jar
|
348
|
+
- tools/pdfbox/preflight-app-3.0.3.jar
|
351
349
|
homepage: ''
|
352
350
|
licenses:
|
353
351
|
- MIT
|
@@ -367,7 +365,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
367
365
|
- !ruby/object:Gem::Version
|
368
366
|
version: '0'
|
369
367
|
requirements: []
|
370
|
-
rubygems_version: 3.
|
368
|
+
rubygems_version: 3.5.18
|
371
369
|
signing_key:
|
372
370
|
specification_version: 4
|
373
371
|
summary: LIBIS File format format services.
|
@@ -1,57 +0,0 @@
|
|
1
|
-
require 'os'
|
2
|
-
|
3
|
-
require 'libis/tools/extend/string'
|
4
|
-
require 'libis/tools/logger'
|
5
|
-
require 'libis/tools/command'
|
6
|
-
|
7
|
-
require 'libis/format/config'
|
8
|
-
|
9
|
-
module Libis
|
10
|
-
module Format
|
11
|
-
module Tool
|
12
|
-
|
13
|
-
class PdfCopy
|
14
|
-
include ::Libis::Tools::Logger
|
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
|
-
|
22
|
-
def self.run(source, target, options = [])
|
23
|
-
self.new.run source, target, options
|
24
|
-
end
|
25
|
-
|
26
|
-
def run(source, target, options = [])
|
27
|
-
|
28
|
-
if OS.java?
|
29
|
-
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
30
|
-
end
|
31
|
-
|
32
|
-
timeout = Libis::Format::Config[:timeouts][:pdf_copy]
|
33
|
-
result = Libis::Tools::Command.run(
|
34
|
-
Libis::Format::Config[:java_cmd],
|
35
|
-
'-cp', Libis::Format::Config[:pdf_tool],
|
36
|
-
'CopyPdf',
|
37
|
-
'--file_input', source,
|
38
|
-
'--file_output', target,
|
39
|
-
*options,
|
40
|
-
timeout: timeout,
|
41
|
-
kill_after: timeout * 2
|
42
|
-
)
|
43
|
-
|
44
|
-
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
45
|
-
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
46
|
-
|
47
|
-
{
|
48
|
-
command: result,
|
49
|
-
files: [ target ]
|
50
|
-
}
|
51
|
-
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'os'
|
2
|
-
|
3
|
-
require 'libis/tools/extend/string'
|
4
|
-
require 'libis/tools/logger'
|
5
|
-
require 'libis/tools/command'
|
6
|
-
|
7
|
-
require 'libis/format/config'
|
8
|
-
|
9
|
-
module Libis
|
10
|
-
module Format
|
11
|
-
module Tool
|
12
|
-
|
13
|
-
class PdfMerge
|
14
|
-
include ::Libis::Tools::Logger
|
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
|
-
|
22
|
-
def self.run(source, target, options = [])
|
23
|
-
self.new.run source, target, options
|
24
|
-
end
|
25
|
-
|
26
|
-
def run(source, target, options = [])
|
27
|
-
source = [source] unless source.is_a?(Array)
|
28
|
-
|
29
|
-
if OS.java?
|
30
|
-
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
31
|
-
end
|
32
|
-
|
33
|
-
timeout = Libis::Format::Config[:timeouts][:pdf_merge]
|
34
|
-
result = Libis::Tools::Command.run(
|
35
|
-
Libis::Format::Config[:java_cmd],
|
36
|
-
'-cp', Libis::Format::Config[:pdf_tool],
|
37
|
-
'MergePdf',
|
38
|
-
'--file_output', target,
|
39
|
-
*options,
|
40
|
-
*source,
|
41
|
-
timeout: timeout,
|
42
|
-
kill_after: timeout * 2
|
43
|
-
)
|
44
|
-
|
45
|
-
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
46
|
-
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
47
|
-
|
48
|
-
{
|
49
|
-
command: result,
|
50
|
-
files: [ target ]
|
51
|
-
}
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'os'
|
4
|
-
|
5
|
-
require 'libis/tools/extend/string'
|
6
|
-
require 'libis/tools/logger'
|
7
|
-
require 'libis/tools/command'
|
8
|
-
|
9
|
-
require 'libis/format/config'
|
10
|
-
|
11
|
-
module Libis
|
12
|
-
module Format
|
13
|
-
module Tool
|
14
|
-
class PdfSplit
|
15
|
-
include ::Libis::Tools::Logger
|
16
|
-
|
17
|
-
def self.installed?
|
18
|
-
result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], '-version')
|
19
|
-
return false unless (result[:status]).zero?
|
20
|
-
|
21
|
-
File.exist?(Libis::Format::Config[:pdf_tool])
|
22
|
-
end
|
23
|
-
|
24
|
-
def self.run(source, target, *args)
|
25
|
-
new.run source, target, *args
|
26
|
-
end
|
27
|
-
|
28
|
-
def run(source, target, *args)
|
29
|
-
if OS.java?
|
30
|
-
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
31
|
-
end
|
32
|
-
|
33
|
-
timeout = Libis::Format::Config[:timeouts][:pdf_split]
|
34
|
-
result = Libis::Tools::Command.run(
|
35
|
-
Libis::Format::Config[:java_cmd],
|
36
|
-
'-cp', Libis::Format::Config[:pdf_tool],
|
37
|
-
'SplitPdf',
|
38
|
-
'--file_input', source,
|
39
|
-
'--file_output', target,
|
40
|
-
*args,
|
41
|
-
timeout:,
|
42
|
-
kill_after: timeout * 2
|
43
|
-
)
|
44
|
-
|
45
|
-
raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
46
|
-
raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty?
|
47
|
-
|
48
|
-
{
|
49
|
-
command: result,
|
50
|
-
files: [target] # TODO: collect the files
|
51
|
-
}
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
Binary file
|