libis-format 2.0.0 → 2.0.1
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 +2 -0
- data/lib/libis/format.rb +7 -1
- data/lib/libis/format/config.rb +1 -0
- data/lib/libis/format/converter/base.rb +1 -0
- data/lib/libis/format/converter/image_splitter.rb +4 -0
- 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 +77 -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/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 +19 -11
- 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: bfe52fc3216a0da8528941b4232c252880006137cc92fe8d42512840f5b7ab7d
|
4
|
+
data.tar.gz: 349303abd8b4d8748960713933f532bae3ca83d45613a79321269497baa6ae2a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '0917e66b03e3bf008dd3a86761f9004d93d1fbc3c02c8c692a1f6f312f25c4edc0a1536b73e4a01043b4e03c85125437ae1307c49349bdee7c46d3f5b2503231'
|
7
|
+
data.tar.gz: 29bd68dce1a8f5f2c0216299b29268d3fdcbafaed4282b7076fac4810762fb377a403dbc08dc23672a3eda4bb17cae8c8882bb24d21980396d3c2943935d1437
|
data/.gitignore
CHANGED
data/lib/libis/format.rb
CHANGED
data/lib/libis/format/config.rb
CHANGED
@@ -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]
|
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]
|
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
|
@@ -0,0 +1,77 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/tool/pdf_select'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Format
|
9
|
+
module Converter
|
10
|
+
|
11
|
+
# noinspection DuplicatedCode
|
12
|
+
class PdfSelecter < 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_select(_)
|
24
|
+
#force usage of this converter
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
@options[:range] = []
|
30
|
+
end
|
31
|
+
|
32
|
+
# Select a partial list of pages
|
33
|
+
# @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
|
34
|
+
def range(selection)
|
35
|
+
@options[:range] << selection unless selection.blank?
|
36
|
+
end
|
37
|
+
|
38
|
+
def convert(source, target, format, opts = {})
|
39
|
+
super
|
40
|
+
|
41
|
+
result = nil
|
42
|
+
|
43
|
+
unless @options.empty?
|
44
|
+
result = convert_pdf(source, target)
|
45
|
+
return nil unless result
|
46
|
+
end
|
47
|
+
|
48
|
+
result
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
def convert_pdf(source, target)
|
53
|
+
|
54
|
+
using_temp(target) do |tmpname|
|
55
|
+
result = Libis::Format::Tool::PdfSelect.run(
|
56
|
+
source, tmpname,
|
57
|
+
@options.map { |k, v|
|
58
|
+
if v.nil?
|
59
|
+
nil
|
60
|
+
else
|
61
|
+
["--#{k}", v]
|
62
|
+
end }.compact.flatten
|
63
|
+
)
|
64
|
+
unless result[:err].empty?
|
65
|
+
error("Pdf selection encountered errors:\n%s", result[:err].join(join("\n")))
|
66
|
+
next nil
|
67
|
+
end
|
68
|
+
tmpname
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -17,20 +17,20 @@ module Libis
|
|
17
17
|
|
18
18
|
def self.output_types(format = nil)
|
19
19
|
return [] unless input_types.include?(format) if format
|
20
|
-
[:
|
21
|
-
end
|
22
|
-
|
23
|
-
def pdf_split(_)
|
24
|
-
#force usage of this converter
|
20
|
+
[:PDFA]
|
25
21
|
end
|
26
22
|
|
27
23
|
def self.category
|
28
24
|
:splitter
|
29
25
|
end
|
30
26
|
|
31
|
-
|
27
|
+
def initialize
|
28
|
+
super
|
29
|
+
end
|
30
|
+
|
31
|
+
# Split at given page. If omitted, nil or 0, the source PDF will be split at every page
|
32
32
|
def page(v)
|
33
|
-
@page = v unless v.blank
|
33
|
+
@options[:page] = v unless v.blank?
|
34
34
|
end
|
35
35
|
|
36
36
|
def convert(source, target, format, opts = {})
|
@@ -46,15 +46,20 @@ module Libis
|
|
46
46
|
|
47
47
|
def split(source, target)
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
49
|
+
result = Libis::Format::Tool::PdfSplit.run(
|
50
|
+
source, target,
|
51
|
+
@options.map { |k, v|
|
52
|
+
if v.nil?
|
53
|
+
nil
|
54
|
+
else
|
55
|
+
["--#{k}", v]
|
56
|
+
end }.compact.flatten
|
57
|
+
)
|
58
|
+
unless result[:err].empty?
|
59
|
+
error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
|
60
|
+
return nil
|
57
61
|
end
|
62
|
+
result[:out]
|
58
63
|
|
59
64
|
end
|
60
65
|
|
@@ -0,0 +1,71 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/tool/pdf_watermark'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Format
|
9
|
+
module Converter
|
10
|
+
|
11
|
+
class PdfWatermarkerHeader < Libis::Format::Converter::Base
|
12
|
+
|
13
|
+
def self.input_types
|
14
|
+
[:PDF]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.output_types(format = nil)
|
18
|
+
return [] unless input_types.include?(format) if format
|
19
|
+
[:PDF]
|
20
|
+
end
|
21
|
+
|
22
|
+
def pdf_watermark_header(_)
|
23
|
+
#force usage of this converter
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
end
|
29
|
+
|
30
|
+
def text(v)
|
31
|
+
@options[:text] = v.blank? ? nil : v
|
32
|
+
end
|
33
|
+
|
34
|
+
def convert(source, target, format, opts = {})
|
35
|
+
super
|
36
|
+
|
37
|
+
result = convert_pdf(source, target)
|
38
|
+
return nil unless result
|
39
|
+
|
40
|
+
result
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
# noinspection DuplicatedCode
|
45
|
+
def convert_pdf(source, target)
|
46
|
+
|
47
|
+
using_temp(target) do |tmpname|
|
48
|
+
result = Libis::Format::Tool::PdfWatermark.run(
|
49
|
+
source, tmpname, 'header',
|
50
|
+
@options.map {|k, v|
|
51
|
+
if v.nil?
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
["--#{k}", v]
|
55
|
+
end
|
56
|
+
}.compact.flatten
|
57
|
+
)
|
58
|
+
unless result[:err].empty?
|
59
|
+
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
60
|
+
next nil
|
61
|
+
end
|
62
|
+
tmpname
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/tool/pdf_watermark'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Format
|
9
|
+
module Converter
|
10
|
+
|
11
|
+
class PdfWatermarkerImage < Libis::Format::Converter::Base
|
12
|
+
|
13
|
+
def self.input_types
|
14
|
+
[:PDF]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.output_types(format = nil)
|
18
|
+
return [] unless input_types.include?(format) if format
|
19
|
+
[:PDF]
|
20
|
+
end
|
21
|
+
|
22
|
+
def pdf_watermark_image(_)
|
23
|
+
#force usage of this converter
|
24
|
+
end
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
super
|
28
|
+
@options[:opacity] = '0.3'
|
29
|
+
end
|
30
|
+
|
31
|
+
def file(v)
|
32
|
+
@file = v
|
33
|
+
end
|
34
|
+
|
35
|
+
def opacity(v)
|
36
|
+
@options[:opacity] = v unless v.blank?
|
37
|
+
end
|
38
|
+
|
39
|
+
def convert(source, target, format, opts = {})
|
40
|
+
super
|
41
|
+
|
42
|
+
result = convert_pdf(source, target)
|
43
|
+
return nil unless result
|
44
|
+
|
45
|
+
result
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
# noinspection DuplicatedCode
|
50
|
+
def convert_pdf(source, target)
|
51
|
+
|
52
|
+
using_temp(target) do |tmpname|
|
53
|
+
result = Libis::Format::Tool::PdfWatermark.run(
|
54
|
+
source, tmpname, 'image',
|
55
|
+
@options.map {|k, v|
|
56
|
+
if v.nil?
|
57
|
+
nil
|
58
|
+
else
|
59
|
+
["--#{k}", v]
|
60
|
+
end
|
61
|
+
}.compact.flatten + [@file]
|
62
|
+
)
|
63
|
+
unless result[:err].empty?
|
64
|
+
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
65
|
+
next nil
|
66
|
+
end
|
67
|
+
tmpname
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -2,16 +2,13 @@
|
|
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_watermark'
|
9
6
|
|
10
7
|
module Libis
|
11
8
|
module Format
|
12
9
|
module Converter
|
13
10
|
|
14
|
-
class
|
11
|
+
class PdfWatermarkerText < Libis::Format::Converter::Base
|
15
12
|
|
16
13
|
def self.input_types
|
17
14
|
[:PDF]
|
@@ -22,22 +19,18 @@ module Libis
|
|
22
19
|
[:PDF]
|
23
20
|
end
|
24
21
|
|
25
|
-
def
|
22
|
+
def pdf_watermark_text(_)
|
26
23
|
#force usage of this converter
|
27
24
|
end
|
28
25
|
|
29
26
|
def initialize
|
30
27
|
super
|
31
|
-
@
|
28
|
+
@text = []
|
32
29
|
@options[:opacity] = '0.3'
|
33
30
|
end
|
34
31
|
|
35
|
-
def file(v)
|
36
|
-
@options[:file] = v.blank? ? nil : v
|
37
|
-
end
|
38
|
-
|
39
32
|
def text(v)
|
40
|
-
@
|
33
|
+
@text += v.split("\n")
|
41
34
|
end
|
42
35
|
|
43
36
|
def rotation(v)
|
@@ -52,12 +45,12 @@ module Libis
|
|
52
45
|
@options[:opacity] = v unless v.blank?
|
53
46
|
end
|
54
47
|
|
55
|
-
def
|
56
|
-
@options[:
|
48
|
+
def gap(v)
|
49
|
+
@options[:gap] = v
|
57
50
|
end
|
58
51
|
|
59
|
-
def
|
60
|
-
@options[:
|
52
|
+
def padding(v)
|
53
|
+
@options[:padding] = v
|
61
54
|
end
|
62
55
|
|
63
56
|
def convert(source, target, format, opts = {})
|
@@ -70,29 +63,19 @@ module Libis
|
|
70
63
|
|
71
64
|
end
|
72
65
|
|
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
66
|
# noinspection DuplicatedCode
|
83
67
|
def convert_pdf(source, target)
|
84
68
|
|
85
69
|
using_temp(target) do |tmpname|
|
86
|
-
result = Libis::Format::Tool::
|
87
|
-
source, tmpname,
|
70
|
+
result = Libis::Format::Tool::PdfWatermark.run(
|
71
|
+
source, tmpname, 'text',
|
88
72
|
@options.map {|k, v|
|
89
73
|
if v.nil?
|
90
74
|
nil
|
91
75
|
else
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
end}.compact.flatten
|
76
|
+
["--#{k}", v]
|
77
|
+
end
|
78
|
+
}.compact.flatten + @text
|
96
79
|
)
|
97
80
|
unless result[:err].empty?
|
98
81
|
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
data/lib/libis/format/tool.rb
CHANGED
@@ -12,10 +12,13 @@ module Libis
|
|
12
12
|
autoload :OfficeToPdf, 'libis/format/tool/office_to_pdf'
|
13
13
|
autoload :FFMpeg, 'libis/format/tool/ffmpeg'
|
14
14
|
autoload :FopPdf, 'libis/format/tool/fop_pdf'
|
15
|
-
autoload :PdfCopy, 'libis/format/tool/pdf_copy'
|
16
15
|
autoload :PdfMerge, 'libis/format/tool/pdf_merge'
|
16
|
+
autoload :PdfMetadata, 'libis/format/tool/pdf_metadata'
|
17
17
|
autoload :PdfOptimizer, 'libis/format/tool/pdf_optimizer'
|
18
|
+
autoload :PdfProtect, 'libis/format/tool/pdf_protect'
|
19
|
+
autoload :PdfSelect, 'libis/format/tool/pdf_select'
|
18
20
|
autoload :PdfSplit, 'libis/format/tool/pdf_split'
|
21
|
+
autoload :PdfWatermark, 'libis/format/tool/pdf_watermark'
|
19
22
|
autoload :PdfToPdfa, 'libis/format/tool/pdf_to_pdfa'
|
20
23
|
autoload :PdfaValidator, 'libis/format/tool/pdfa_validator'
|
21
24
|
|
@@ -27,9 +27,9 @@ module Libis
|
|
27
27
|
timeout = Libis::Format::Config[:timeouts][:pdf_merge]
|
28
28
|
result = Libis::Tools::Command.run(
|
29
29
|
Libis::Format::Config[:java_cmd],
|
30
|
-
'-
|
31
|
-
'
|
32
|
-
'
|
30
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
31
|
+
'merge',
|
32
|
+
'-o', target,
|
33
33
|
*options,
|
34
34
|
*source,
|
35
35
|
timeout: timeout,
|
@@ -10,7 +10,7 @@ module Libis
|
|
10
10
|
module Format
|
11
11
|
module Tool
|
12
12
|
|
13
|
-
class
|
13
|
+
class PdfMetadata
|
14
14
|
include ::Libis::Tools::Logger
|
15
15
|
|
16
16
|
def self.run(source, target, options = [])
|
@@ -26,10 +26,10 @@ module Libis
|
|
26
26
|
timeout = Libis::Format::Config[:timeouts][:pdf_copy]
|
27
27
|
result = Libis::Tools::Command.run(
|
28
28
|
Libis::Format::Config[:java_cmd],
|
29
|
-
'-
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
29
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
30
|
+
'metadata',
|
31
|
+
'-i', source,
|
32
|
+
'-o', target,
|
33
33
|
*options,
|
34
34
|
timeout: timeout,
|
35
35
|
kill_after: timeout * 2
|
@@ -0,0 +1,47 @@
|
|
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 PdfProtect
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, options = [])
|
17
|
+
self.new.run source, target, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, options = [])
|
21
|
+
|
22
|
+
if OS.java?
|
23
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
24
|
+
end
|
25
|
+
|
26
|
+
timeout = Libis::Format::Config[:timeouts][:pdf_copy]
|
27
|
+
result = Libis::Tools::Command.run(
|
28
|
+
Libis::Format::Config[:java_cmd],
|
29
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
30
|
+
'protect',
|
31
|
+
'-i', source,
|
32
|
+
'-o', target,
|
33
|
+
*options,
|
34
|
+
timeout: timeout,
|
35
|
+
kill_after: timeout * 2
|
36
|
+
)
|
37
|
+
|
38
|
+
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
39
|
+
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,47 @@
|
|
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 PdfSelect
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, options = [])
|
17
|
+
self.new.run source, target, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, options = [])
|
21
|
+
|
22
|
+
if OS.java?
|
23
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
24
|
+
end
|
25
|
+
|
26
|
+
timeout = Libis::Format::Config[:timeouts][:pdf_select]
|
27
|
+
result = Libis::Tools::Command.run(
|
28
|
+
Libis::Format::Config[:java_cmd],
|
29
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
30
|
+
'select',
|
31
|
+
'-i', source,
|
32
|
+
'-o', target,
|
33
|
+
*options,
|
34
|
+
timeout: timeout,
|
35
|
+
kill_after: timeout * 2
|
36
|
+
)
|
37
|
+
|
38
|
+
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
39
|
+
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -26,10 +26,10 @@ module Libis
|
|
26
26
|
timeout = Libis::Format::Config[:timeouts][:pdf_split]
|
27
27
|
result = Libis::Tools::Command.run(
|
28
28
|
Libis::Format::Config[:java_cmd],
|
29
|
-
'-
|
30
|
-
'
|
31
|
-
'
|
32
|
-
'
|
29
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
30
|
+
'split',
|
31
|
+
'-i', source,
|
32
|
+
'-o', target,
|
33
33
|
*options,
|
34
34
|
timeout: timeout,
|
35
35
|
kill_after: timeout * 2
|
@@ -0,0 +1,47 @@
|
|
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 PdfWatermark
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(source, target, wm_type, options = [])
|
17
|
+
self.new.run source, target, wm_type, options
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(source, target, wm_type, options = [])
|
21
|
+
|
22
|
+
if OS.java?
|
23
|
+
# TODO: import library and execute in current VM. For now do exactly as in MRI.
|
24
|
+
end
|
25
|
+
|
26
|
+
timeout = Libis::Format::Config[:timeouts][:pdf_watermark]
|
27
|
+
result = Libis::Tools::Command.run(
|
28
|
+
Libis::Format::Config[:java_cmd],
|
29
|
+
'-jar', Libis::Format::Config[:pdf_tool],
|
30
|
+
'watermark', wm_type,
|
31
|
+
'-i', source,
|
32
|
+
'-o', target,
|
33
|
+
*options,
|
34
|
+
timeout: timeout,
|
35
|
+
kill_after: timeout * 2
|
36
|
+
)
|
37
|
+
|
38
|
+
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
|
39
|
+
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
|
40
|
+
|
41
|
+
result
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
data/lib/libis/format/version.rb
CHANGED
data/libis-format.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.add_development_dependency 'nokogiri'
|
34
34
|
end
|
35
35
|
|
36
|
-
spec.add_runtime_dependency 'libis-tools', '
|
36
|
+
spec.add_runtime_dependency 'libis-tools', '>= 1.0.9'
|
37
37
|
spec.add_runtime_dependency 'os', '= 0.9.6'
|
38
38
|
spec.add_runtime_dependency 'mini_magick', '~> 4.3'
|
39
39
|
spec.add_runtime_dependency 'deep_dive', '~> 0.3'
|
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: 2.0.
|
4
|
+
version: 2.0.1
|
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: 2021-02-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -84,16 +84,16 @@ dependencies:
|
|
84
84
|
name: libis-tools
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - "
|
87
|
+
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.0.9
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - "
|
94
|
+
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.0.9
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: os
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -222,9 +222,14 @@ files:
|
|
222
222
|
- lib/libis/format/converter/office_converter.rb
|
223
223
|
- lib/libis/format/converter/pdf_assembler.rb
|
224
224
|
- lib/libis/format/converter/pdf_converter.rb
|
225
|
+
- lib/libis/format/converter/pdf_metadata.rb
|
225
226
|
- lib/libis/format/converter/pdf_optimizer.rb
|
227
|
+
- lib/libis/format/converter/pdf_protecter.rb
|
228
|
+
- lib/libis/format/converter/pdf_selecter.rb
|
226
229
|
- lib/libis/format/converter/pdf_splitter.rb
|
227
|
-
- lib/libis/format/converter/
|
230
|
+
- lib/libis/format/converter/pdf_watermarker_header.rb
|
231
|
+
- lib/libis/format/converter/pdf_watermarker_image.rb
|
232
|
+
- lib/libis/format/converter/pdf_watermarker_text.rb
|
228
233
|
- lib/libis/format/converter/repository.rb
|
229
234
|
- lib/libis/format/converter/spreadsheet_converter.rb
|
230
235
|
- lib/libis/format/converter/video_converter.rb
|
@@ -241,19 +246,22 @@ files:
|
|
241
246
|
- lib/libis/format/tool/fop_pdf.rb
|
242
247
|
- lib/libis/format/tool/identification_tool.rb
|
243
248
|
- lib/libis/format/tool/office_to_pdf.rb
|
244
|
-
- lib/libis/format/tool/pdf_copy.rb
|
245
249
|
- lib/libis/format/tool/pdf_merge.rb
|
250
|
+
- lib/libis/format/tool/pdf_metadata.rb
|
246
251
|
- lib/libis/format/tool/pdf_optimizer.rb
|
252
|
+
- lib/libis/format/tool/pdf_protect.rb
|
253
|
+
- lib/libis/format/tool/pdf_select.rb
|
247
254
|
- lib/libis/format/tool/pdf_split.rb
|
248
255
|
- lib/libis/format/tool/pdf_to_pdfa.rb
|
256
|
+
- lib/libis/format/tool/pdf_watermark.rb
|
249
257
|
- lib/libis/format/tool/pdfa_validator.rb
|
250
258
|
- lib/libis/format/tool/spreadsheet_to_ods.rb
|
251
259
|
- lib/libis/format/version.rb
|
252
260
|
- lib/libis/format/yaml_loader.rb
|
253
261
|
- libis-format.gemspec
|
254
262
|
- tools/PdfTool.jar
|
255
|
-
- tools/bcpkix-jdk15on-
|
256
|
-
- tools/bcprov-jdk15on-
|
263
|
+
- tools/bcpkix-jdk15on-167.jar
|
264
|
+
- tools/bcprov-jdk15on-167.jar
|
257
265
|
- tools/fop/build/fop.jar
|
258
266
|
- tools/fop/conf/fop.xconf
|
259
267
|
- tools/fop/fop
|
@@ -325,7 +333,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
325
333
|
- !ruby/object:Gem::Version
|
326
334
|
version: '0'
|
327
335
|
requirements: []
|
328
|
-
rubygems_version: 3.
|
336
|
+
rubygems_version: 3.1.4
|
329
337
|
signing_key:
|
330
338
|
specification_version: 4
|
331
339
|
summary: LIBIS File format format services.
|
Binary file
|
Binary file
|