libis-format 0.9.3 → 0.9.4
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/lib/libis/format/converter/base.rb +2 -1
- data/lib/libis/format/converter/chain.rb +14 -26
- data/lib/libis/format/converter/image_converter.rb +7 -4
- data/lib/libis/format/converter/office_converter.rb +4 -0
- data/lib/libis/format/converter/pdf_converter.rb +34 -5
- data/lib/libis/format/converter/repository.rb +6 -6
- data/lib/libis/format/pdf_copy.rb +12 -22
- data/lib/libis/format/pdf_merge.rb +41 -0
- data/lib/libis/format/pdf_split.rb +39 -0
- data/lib/libis/format/pdf_to_pdfa.rb +3 -6
- data/lib/libis/format/version.rb +1 -1
- data/lib/libis/format.rb +2 -0
- data/tools/PdfTool.jar +0 -0
- data/tools/bcpkix-jdk15on-1.49.jar +0 -0
- data/tools/bcprov-jdk15on-1.49.jar +0 -0
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52d5e68539643d115a5666c130f68af4951cf2cf
|
4
|
+
data.tar.gz: 231e887b8ef18a2623f7eed16f14ece3ebd304d2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 838b921e071bdbaa16dc140162af0e192551adbc27eca5ce0f7b35ef5f10e01f5beb6822f62a03995310bb77d180bc9f21da5803f72433707358abbeccf01d9e
|
7
|
+
data.tar.gz: 2ab0af8ffd4bc2c02e42c7086898101b80558046c5fc20155fa9b5b85ae730b4f559f59c880911449ab0b31c1fee775c43090f2057d2a4861ee4907491dea4fa
|
@@ -38,8 +38,9 @@ module Libis
|
|
38
38
|
raise RuntimeError, 'Method #output_types needs to be overridden in converter'
|
39
39
|
end
|
40
40
|
|
41
|
+
|
41
42
|
def using_temp(target)
|
42
|
-
tempfile = File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname(['convert', File.extname(target)], File.basename(target, '.*')))
|
43
|
+
tempfile = File.join(Dir.tmpdir, Dir::Tmpname.make_tmpname(['convert', File.extname(target)], File.basename(target, '.*').gsub(/\s/, '_')))
|
43
44
|
result = yield tempfile
|
44
45
|
return nil unless result
|
45
46
|
FileUtils.move result, target
|
@@ -4,6 +4,7 @@ require 'fileutils'
|
|
4
4
|
require 'deep_dive'
|
5
5
|
|
6
6
|
require 'libis/tools/logger'
|
7
|
+
require 'libis/tools/extend/hash'
|
7
8
|
require 'libis/format/type_database'
|
8
9
|
|
9
10
|
module Libis
|
@@ -15,9 +16,9 @@ module Libis
|
|
15
16
|
include DeepDive
|
16
17
|
|
17
18
|
def initialize(source_format, target_format, operations = {})
|
18
|
-
@source_format = source_format
|
19
|
-
@target_format = target_format
|
20
|
-
@operations = operations
|
19
|
+
@source_format = source_format.to_sym
|
20
|
+
@target_format = target_format.to_sym
|
21
|
+
@operations = operations || {}
|
21
22
|
@converter_chain = []
|
22
23
|
end
|
23
24
|
|
@@ -32,8 +33,8 @@ module Libis
|
|
32
33
|
|
33
34
|
def closed?
|
34
35
|
!@converter_chain.empty? &&
|
35
|
-
@converter_chain.first[:input] == @source_format &&
|
36
|
-
@converter_chain.last[:output] == @target_format
|
36
|
+
@converter_chain.first[:input].to_sym == @source_format &&
|
37
|
+
@converter_chain.last[:output].to_sym == @target_format
|
37
38
|
end
|
38
39
|
|
39
40
|
def valid?
|
@@ -51,21 +52,11 @@ module Libis
|
|
51
52
|
alias_method :length, :size
|
52
53
|
|
53
54
|
def to_s
|
54
|
-
# nodes_string = @converter_chain.map do |node|
|
55
|
-
# node_name = node[:converter].name.gsub(/^.*::/,'')
|
56
|
-
# node_operations = '(' + node[:operations].map do |operation|
|
57
|
-
# op = "#{operation[:method]}:#{operation[:argument]}"
|
58
|
-
# op
|
59
|
-
# end.join(', ') + ')' rescue ''
|
60
|
-
# node_string = "#{node_name}#{node_operations}->-#{node[:output]}"
|
61
|
-
# node_string
|
62
|
-
# end.join('->-')
|
63
|
-
# "#{@source_format}->-#{nodes_string}"
|
64
55
|
"#{@source_format}->-#{@converter_chain.map do |node|
|
65
|
-
"#{node[:converter].name.gsub(/^.*::/,'')}#{node[:operations] ?
|
66
|
-
"(#{node[:operations].each
|
67
|
-
|
68
|
-
|
56
|
+
"#{node[:converter].name.gsub(/^.*::/, '')}#{node[:operations].empty? ? '' :
|
57
|
+
"(#{node[:operations].each do |operation|
|
58
|
+
"#{operation[:method]}:#{operation[:argument]}"
|
59
|
+
end.join(',')})"}->-#{node[:output]}"
|
69
60
|
end.join('->-')}"
|
70
61
|
end
|
71
62
|
|
@@ -87,11 +78,11 @@ module Libis
|
|
87
78
|
|
88
79
|
node[:operations].each do |operation|
|
89
80
|
converter.send operation[:method], operation[:argument]
|
90
|
-
end
|
81
|
+
end if node[:operations]
|
91
82
|
|
92
83
|
target = target_file
|
93
84
|
|
94
|
-
if i < size
|
85
|
+
if i < size - 1
|
95
86
|
target += ".temp.#{TypeDatabase.type_extentions(target_type).first}"
|
96
87
|
target += ".#{TypeDatabase.type_extentions(target_type).first}" while File.exist? target
|
97
88
|
temp_files << target
|
@@ -114,7 +105,6 @@ module Libis
|
|
114
105
|
end
|
115
106
|
|
116
107
|
def valid_chain_nodes(converter)
|
117
|
-
return [] if closed?
|
118
108
|
source_format = @converter_chain.last[:output] rescue @source_format
|
119
109
|
nodes = []
|
120
110
|
if converter.input_types.include? source_format
|
@@ -128,7 +118,6 @@ module Libis
|
|
128
118
|
end
|
129
119
|
|
130
120
|
def add_chain_node(node = {})
|
131
|
-
return nil if closed?
|
132
121
|
last_converter = @converter_chain.last
|
133
122
|
source_format = last_converter ? last_converter[:output] : @source_format
|
134
123
|
node[:input] ||= source_format
|
@@ -142,12 +131,11 @@ module Libis
|
|
142
131
|
end
|
143
132
|
|
144
133
|
def apply_operations
|
145
|
-
return false unless closed?
|
146
134
|
temp_chain = @converter_chain.reverse.ddup
|
147
135
|
applied = true
|
148
|
-
operations = @operations.ddup
|
136
|
+
operations = @operations && @operations.ddup || {}
|
149
137
|
while (operation = operations.shift)
|
150
|
-
method = operation.first.to_s.
|
138
|
+
method = operation.first.to_s.to_sym
|
151
139
|
applied &&= :found == temp_chain.each do |node|
|
152
140
|
next unless node[:converter].instance_methods.include?(method)
|
153
141
|
node[:operations] ||= []
|
@@ -4,6 +4,7 @@ require_relative 'base'
|
|
4
4
|
require 'libis/format/identifier'
|
5
5
|
|
6
6
|
require 'mini_magick'
|
7
|
+
require 'fileutils'
|
7
8
|
|
8
9
|
MiniMagick.configure do |config|
|
9
10
|
config.debug = false
|
@@ -28,7 +29,7 @@ module Libis
|
|
28
29
|
super
|
29
30
|
end
|
30
31
|
|
31
|
-
def
|
32
|
+
def image_convert(_)
|
32
33
|
#force usage of this converter
|
33
34
|
end
|
34
35
|
|
@@ -79,10 +80,10 @@ module Libis
|
|
79
80
|
def watermark(options = {})
|
80
81
|
text = options[:text] || '© LIBIS'
|
81
82
|
image = options[:file] || (Dir::Tmpname.create(%w(wm_image .png)) { |_|})
|
82
|
-
@wm_size = (options[:size] || '4').
|
83
|
-
@wm_opacity = ((options[:opacity] || 0.1).to_f * 100).
|
83
|
+
@wm_size = (options[:size] || '4').to_i
|
84
|
+
@wm_opacity = ((options[:opacity] || 0.1).to_f * 100).to_i
|
84
85
|
@wm_composition = options[:composition] || 'modulate'
|
85
|
-
gap = ((options[:gap] || 0.2).to_f * 100).
|
86
|
+
gap = ((options[:gap] || 0.2).to_f * 100).to_i
|
86
87
|
rotation = 360 - (options[:rotation] || 30).to_i
|
87
88
|
@wm_image = MiniMagick::Image.new(image)
|
88
89
|
unless @wm_image.valid?
|
@@ -116,6 +117,8 @@ module Libis
|
|
116
117
|
def convert(source, target, format, opts = {})
|
117
118
|
super
|
118
119
|
|
120
|
+
FileUtils.mkpath(File.dirname(target))
|
121
|
+
|
119
122
|
if source.is_a? Array
|
120
123
|
sources = source
|
121
124
|
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
4
|
|
5
|
+
require 'libis/tools/extend/hash'
|
5
6
|
require 'libis/format/pdf_copy'
|
6
7
|
require 'libis/format/pdf_to_pdfa'
|
7
8
|
|
@@ -19,6 +20,10 @@ module Libis
|
|
19
20
|
[:PDF, :PDFA]
|
20
21
|
end
|
21
22
|
|
23
|
+
def pdf_convert(_)
|
24
|
+
#force usage of this converter
|
25
|
+
end
|
26
|
+
|
22
27
|
# Set metadata for Pdf file
|
23
28
|
#
|
24
29
|
# valid metadata keys are):
|
@@ -30,8 +35,9 @@ module Libis
|
|
30
35
|
#
|
31
36
|
# @param [Hash] values list of metadata values to set
|
32
37
|
def metadata(values = {})
|
38
|
+
values.key_strings_to_symbols!
|
33
39
|
values.each do |k, v|
|
34
|
-
next unless [:title, :author, :creator, :keywords, :subject].include?(k
|
40
|
+
next unless [:title, :author, :creator, :keywords, :subject].include?(k)
|
35
41
|
@options["md_#{k}"] = v
|
36
42
|
end
|
37
43
|
end
|
@@ -59,6 +65,7 @@ module Libis
|
|
59
65
|
#
|
60
66
|
# @param [Hash] options Hash of options for watermark creation.
|
61
67
|
def watermark(options = {})
|
68
|
+
options.key_strings_to_symbols!
|
62
69
|
if options[:file] && File.exist?(options[:file])
|
63
70
|
@options['wm_image'] = options[:file]
|
64
71
|
else
|
@@ -66,7 +73,7 @@ module Libis
|
|
66
73
|
@options['wm_text_rotation'] = options[:rotation] if options[:rotation]
|
67
74
|
@options['wm_font_size'] = options[:size] if options[:size]
|
68
75
|
end
|
69
|
-
@options['wm_opacity'] = options[:opacity]
|
76
|
+
@options['wm_opacity'] = options[:opacity] || '0.3'
|
70
77
|
@options['wm_gap_ratio'] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
|
71
78
|
@options['wm_gap_size'] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
|
72
79
|
end
|
@@ -77,7 +84,7 @@ module Libis
|
|
77
84
|
result = nil
|
78
85
|
|
79
86
|
unless @options.empty?
|
80
|
-
result
|
87
|
+
result = convert_pdf(source, target)
|
81
88
|
return nil unless result
|
82
89
|
source = result
|
83
90
|
end
|
@@ -93,13 +100,35 @@ module Libis
|
|
93
100
|
|
94
101
|
def convert_pdf(source, target)
|
95
102
|
|
96
|
-
using_temp(target)
|
103
|
+
using_temp(target) do |tmpname|
|
104
|
+
result = Libis::Format::PdfCopy.run(
|
105
|
+
source, tmpname,
|
106
|
+
@options.map { |k, v|
|
107
|
+
if v.nil?
|
108
|
+
nil
|
109
|
+
else
|
110
|
+
["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
|
111
|
+
end }.flatten
|
112
|
+
)
|
113
|
+
result[:err].empty? ? target : begin
|
114
|
+
error("Pdf conversion encountered errors:\n%s", result[:err].join('\n'))
|
115
|
+
nil
|
116
|
+
end
|
117
|
+
tmpname
|
118
|
+
end
|
97
119
|
|
98
120
|
end
|
99
121
|
|
100
122
|
def pdf_to_pdfa(source, target)
|
101
123
|
|
102
|
-
using_temp(target)
|
124
|
+
using_temp(target) do |tmpname|
|
125
|
+
result = Libis::Format::PdfToPdfa.run source, tmpname
|
126
|
+
result[:status] == 0 ? target : begin
|
127
|
+
error("Pdf/A conversion encountered errors:\n%s", result[:err].join('\n'))
|
128
|
+
nil
|
129
|
+
end
|
130
|
+
tmpname
|
131
|
+
end
|
103
132
|
|
104
133
|
end
|
105
134
|
|
@@ -49,16 +49,16 @@ module Libis
|
|
49
49
|
def get_converter_chain(src_type, tgt_type, operations = {})
|
50
50
|
msg = "conversion from #{src_type.to_s} to #{tgt_type.to_s}"
|
51
51
|
chain_list = find_chains src_type, tgt_type, operations
|
52
|
-
if chain_list.length > 1
|
53
|
-
|
54
|
-
end
|
52
|
+
# if chain_list.length > 1
|
53
|
+
# warn "Found more than one conversion chain for #{msg}. Picking the first one."
|
54
|
+
# end
|
55
55
|
if chain_list.empty?
|
56
56
|
error "No conversion chain found for #{msg}"
|
57
57
|
return nil
|
58
58
|
end
|
59
|
-
chain_list.each do |chain|
|
60
|
-
|
61
|
-
end
|
59
|
+
# chain_list.each do |chain|
|
60
|
+
# debug "Matched chain: #{chain}"
|
61
|
+
# end
|
62
62
|
chain_list[0]
|
63
63
|
end
|
64
64
|
|
@@ -19,30 +19,20 @@ module Libis
|
|
19
19
|
def run(source, target, options = [])
|
20
20
|
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
21
21
|
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
22
|
+
|
22
23
|
if OS.java?
|
23
|
-
# TODO: import library and execute in current VM. For now do exactly as in MRI
|
24
|
-
result = Libis::Tools::Command.run(
|
25
|
-
Libis::Format::Config[:java_path],
|
26
|
-
'-jar', jar_file,
|
27
|
-
'CopyPdf',
|
28
|
-
'--file_input', source,
|
29
|
-
'--file_output', target,
|
30
|
-
*options
|
31
|
-
)
|
32
|
-
warn "PdfCopy errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
33
|
-
result[:out]
|
34
|
-
else
|
35
|
-
result = Libis::Tools::Command.run(
|
36
|
-
Libis::Format::Config[:java_path],
|
37
|
-
'-jar', jar_file,
|
38
|
-
'CopyPdf',
|
39
|
-
'--file_input', source,
|
40
|
-
'--file_output', target,
|
41
|
-
*options
|
42
|
-
)
|
43
|
-
warn "PdfCopy errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
44
|
-
result[:out]
|
24
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
45
25
|
end
|
26
|
+
|
27
|
+
Libis::Tools::Command.run(
|
28
|
+
Libis::Format::Config[:java_path],
|
29
|
+
'-cp', jar_file,
|
30
|
+
'CopyPdf',
|
31
|
+
'--file_input', source,
|
32
|
+
'--file_output', target,
|
33
|
+
*options
|
34
|
+
)
|
35
|
+
|
46
36
|
end
|
47
37
|
end
|
48
38
|
|
@@ -0,0 +1,41 @@
|
|
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
|
+
|
12
|
+
class PdfMerge
|
13
|
+
include ::Libis::Tools::Logger
|
14
|
+
|
15
|
+
def self.run(source, target, options = [])
|
16
|
+
self.new.run source, target, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(source, target, options = [])
|
20
|
+
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
21
|
+
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
22
|
+
source = [source] unless source.is_a?(Array)
|
23
|
+
|
24
|
+
if OS.java?
|
25
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
26
|
+
end
|
27
|
+
|
28
|
+
Libis::Tools::Command.run(
|
29
|
+
Libis::Format::Config[:java_path],
|
30
|
+
'-cp', jar_file,
|
31
|
+
'MergePdf',
|
32
|
+
'--file_output', target,
|
33
|
+
*options,
|
34
|
+
*source,
|
35
|
+
)
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,39 @@
|
|
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
|
+
|
12
|
+
class PdfSplit
|
13
|
+
include ::Libis::Tools::Logger
|
14
|
+
|
15
|
+
def self.run(source, target, options = [])
|
16
|
+
self.new.run source, target, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(source, target, options = [])
|
20
|
+
tool_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'tools'))
|
21
|
+
jar_file = File.join(tool_dir, 'PdfTool.jar')
|
22
|
+
if OS.java?
|
23
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
24
|
+
end
|
25
|
+
|
26
|
+
Libis::Tools::Command.run(
|
27
|
+
Libis::Format::Config[:java_path],
|
28
|
+
'-cp', jar_file,
|
29
|
+
'SplitPdf',
|
30
|
+
'--file_input', source,
|
31
|
+
'--file_output', target,
|
32
|
+
*options
|
33
|
+
)
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -49,16 +49,13 @@ module Libis
|
|
49
49
|
)
|
50
50
|
|
51
51
|
FileUtils.rm [icc_file, def_filename].compact, force: true
|
52
|
-
unless result[:status] == 0
|
53
|
-
warn (['Pdf2PdfA errors:'] + result[:err] + result[:out]).join("\n").gsub('%', '%%')
|
54
|
-
end
|
55
52
|
|
56
53
|
unless PdfaValidator.run(target)
|
57
|
-
|
58
|
-
|
54
|
+
result[:status] = -999
|
55
|
+
result[:err] << 'Failed to validate generated PDF/A file.'
|
59
56
|
end
|
60
57
|
|
61
|
-
|
58
|
+
result
|
62
59
|
end
|
63
60
|
|
64
61
|
|
data/lib/libis/format/version.rb
CHANGED
data/lib/libis/format.rb
CHANGED
@@ -9,6 +9,8 @@ module Libis
|
|
9
9
|
autoload :Droid, 'libis/format/droid'
|
10
10
|
autoload :OfficeToPdf, 'libis/format/office_to_pdf'
|
11
11
|
autoload :PdfCopy, 'libis/format/pdf_copy'
|
12
|
+
autoload :PdfMerge, 'libis/format/pdf_merge'
|
13
|
+
autoload :PdfSplit, 'libis/format/pdf_split'
|
12
14
|
autoload :PdfToPdfa, 'libis/format/pdf_to_pdfa'
|
13
15
|
autoload :PdfaValidator, 'libis/format/pdfa_validator'
|
14
16
|
|
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: 0.9.
|
4
|
+
version: 0.9.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -164,6 +164,8 @@ files:
|
|
164
164
|
- lib/libis/format/identifier.rb
|
165
165
|
- lib/libis/format/office_to_pdf.rb
|
166
166
|
- lib/libis/format/pdf_copy.rb
|
167
|
+
- lib/libis/format/pdf_merge.rb
|
168
|
+
- lib/libis/format/pdf_split.rb
|
167
169
|
- lib/libis/format/pdf_to_pdfa.rb
|
168
170
|
- lib/libis/format/pdfa_validator.rb
|
169
171
|
- lib/libis/format/type_database.rb
|
@@ -202,6 +204,8 @@ files:
|
|
202
204
|
- spec/test_types.yml
|
203
205
|
- spec/type_database_spec.rb
|
204
206
|
- tools/PdfTool.jar
|
207
|
+
- tools/bcpkix-jdk15on-1.49.jar
|
208
|
+
- tools/bcprov-jdk15on-1.49.jar
|
205
209
|
- tools/droid/DROID_SignatureFile_V82.xml
|
206
210
|
- tools/droid/container-signature-20150307.xml
|
207
211
|
- tools/droid/droid-command-line-6.1.5.jar
|
@@ -354,7 +358,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
354
358
|
version: '0'
|
355
359
|
requirements: []
|
356
360
|
rubyforge_project:
|
357
|
-
rubygems_version: 2.
|
361
|
+
rubygems_version: 2.2.2
|
358
362
|
signing_key:
|
359
363
|
specification_version: 4
|
360
364
|
summary: LIBIS File format format services.
|