libis-format 1.3.0 → 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 -10
- 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/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 +22 -20
- 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 +40 -153
- 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 +50 -111
- 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 +15 -24
- data/lib/libis/format/tool/pdf_merge.rb +14 -24
- data/lib/libis/format/tool/pdf_optimizer.rb +17 -24
- data/lib/libis/format/tool/pdf_split.rb +16 -25
- data/lib/libis/format/tool/pdf_to_pdfa.rb +32 -50
- data/lib/libis/format/tool/pdfa_validator.rb +30 -25
- 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
- metadata +78 -120
- 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/type_database.rb +0 -156
- data/lib/libis/format/type_database_impl.rb +0 -153
- data/tools/pdf2pdfa +0 -395
- /data/bin/{droid_tool → droid} +0 -0
- /data/bin/{fido_tool → fido} +0 -0
@@ -1,5 +1,4 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# encoding: utf-8
|
3
2
|
require 'libis-tools'
|
4
3
|
require 'fileutils'
|
5
4
|
require 'libis/format/config'
|
@@ -8,31 +7,32 @@ require_relative 'base'
|
|
8
7
|
module Libis
|
9
8
|
module Format
|
10
9
|
module Converter
|
10
|
+
|
11
11
|
class Jp2Converter < Libis::Format::Converter::Base
|
12
|
+
|
12
13
|
def self.input_types
|
13
|
-
|
14
|
+
[:TIFF, :JPG, :PNG, :BMP, :GIF, :PDF]
|
14
15
|
end
|
15
16
|
|
16
17
|
def self.output_types(format = nil)
|
17
|
-
return [] unless input_types.include?(format)
|
18
|
-
|
18
|
+
return [] unless input_types.include?(format) if format
|
19
19
|
[:JP2]
|
20
20
|
end
|
21
21
|
|
22
22
|
def initialize
|
23
23
|
super
|
24
24
|
@options = {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
color_xform: false,
|
26
|
+
error_resilience: :ALL,
|
27
|
+
lossless: true,
|
28
|
+
progression_order: 'RLCP',
|
29
|
+
tile_size: [1024, 1024],
|
30
|
+
codeblock_size: [6, 6],
|
31
31
|
}
|
32
32
|
end
|
33
33
|
|
34
34
|
def j2kdriver(_)
|
35
|
-
#
|
35
|
+
#force usage of this converter
|
36
36
|
end
|
37
37
|
|
38
38
|
def color_xform(flag = true)
|
@@ -68,36 +68,38 @@ module Libis
|
|
68
68
|
|
69
69
|
@options.each do |key, value|
|
70
70
|
case key
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
71
|
+
when :color_xform
|
72
|
+
options << '--set-output-j2k-color-xform' << (value ? 'YES' : 'NO')
|
73
|
+
when :error_resilience
|
74
|
+
options << '--set-output-j2k-error-resilience' << value.to_s
|
75
|
+
when :lossless
|
76
|
+
if value
|
77
|
+
options << '--set-output-j2k-xform' << 'R53' << '5' << '--set-output-j2k-ratio' << '0'
|
78
|
+
else
|
79
|
+
options << '--set-output-j2k-xform' << 'I97' << '--set-output-j2k-psnr' << '46'
|
80
|
+
end
|
81
|
+
when :progression_order
|
82
|
+
options << '--set-output-j2k-progression-order' << value.to_s
|
83
|
+
when :tile_size
|
84
|
+
options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
|
85
|
+
when :codeblock_size
|
86
|
+
options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
|
78
87
|
else
|
79
|
-
|
80
|
-
end
|
81
|
-
when :progression_order
|
82
|
-
options << '--set-output-j2k-progression-order' << value.to_s
|
83
|
-
when :tile_size
|
84
|
-
options << '--set-output-j2k-tile-size' << value[0].to_s << value[1].to_s
|
85
|
-
when :codeblock_size
|
86
|
-
options << '--set-output-j2k-codeblock-size' << value[0].to_s << value[1].to_s
|
87
|
-
else # rubocop:disable Style/EmptyElse
|
88
|
-
# do nothing
|
88
|
+
#do nothing
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
92
|
+
|
93
|
+
Libis::Tools::Command.run(
|
94
|
+
Libis::Format::Config[:j2k_cmd],
|
95
|
+
'--input-file-name', source,
|
96
|
+
'--set-output-type', 'JP2',
|
97
|
+
*options,
|
98
|
+
'--output-file-name', target,
|
99
|
+
|
98
100
|
)
|
99
101
|
|
100
|
-
|
102
|
+
target
|
101
103
|
end
|
102
104
|
end
|
103
105
|
end
|
@@ -1,50 +1,56 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
4
|
|
5
5
|
require 'libis/format/tool/office_to_pdf'
|
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 OfficeConverter < Libis::Format::Converter::Base
|
13
|
+
|
12
14
|
def self.input_types
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
15
|
+
[
|
16
|
+
:TXT,
|
17
|
+
:RTF,
|
18
|
+
:HTML,
|
19
|
+
:MSDOC,
|
20
|
+
:MSDOT,
|
21
|
+
:MSXLS,
|
22
|
+
:MSPPT,
|
23
|
+
:MSDOCX,
|
24
|
+
:MSDOTX,
|
25
|
+
:MSXLSX,
|
26
|
+
:MSPPTX,
|
27
|
+
:WORDPERFECT,
|
28
|
+
:OO_WRITER,
|
29
|
+
:OO_IMPRESS,
|
30
|
+
:OO_CALC
|
29
31
|
]
|
30
32
|
end
|
31
33
|
|
32
34
|
def self.output_types(format = nil)
|
33
|
-
return [] unless input_types.include?(format)
|
34
|
-
|
35
|
+
return [] unless input_types.include?(format) if format
|
35
36
|
[:PDF]
|
36
37
|
end
|
37
38
|
|
38
39
|
def office_convert(_)
|
39
|
-
#
|
40
|
+
#force usage of this converter
|
40
41
|
end
|
41
42
|
|
42
43
|
def convert(source, target, format, opts = {})
|
43
44
|
super
|
44
45
|
|
45
|
-
Format::Tool::OfficeToPdf.run(source, target)
|
46
|
+
return nil unless Format::Tool::OfficeToPdf.run(source, target)
|
47
|
+
|
48
|
+
target
|
49
|
+
|
46
50
|
end
|
51
|
+
|
47
52
|
end
|
53
|
+
|
48
54
|
end
|
49
55
|
end
|
50
56
|
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/tool/pdf_merge'
|
6
|
+
|
7
|
+
module Libis
|
8
|
+
module Format
|
9
|
+
module Converter
|
10
|
+
|
11
|
+
# noinspection DuplicatedCode
|
12
|
+
class PdfAssembler < 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 self.category
|
24
|
+
:assembler
|
25
|
+
end
|
26
|
+
|
27
|
+
def pdf_assemnble(_)
|
28
|
+
#force usage of this converter
|
29
|
+
end
|
30
|
+
|
31
|
+
def convert(source, target, format, opts = {})
|
32
|
+
super
|
33
|
+
|
34
|
+
result = if source.is_a? Array
|
35
|
+
assemble(source, target)
|
36
|
+
elsif File.directory?(source)
|
37
|
+
source_list = Dir[File.join(source, '**', '*')].reject {|p| File.directory? p}
|
38
|
+
assemble(source_list, target)
|
39
|
+
else
|
40
|
+
assemble([source], target)
|
41
|
+
end
|
42
|
+
return nil unless result
|
43
|
+
|
44
|
+
result
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def assemble(source, target)
|
50
|
+
|
51
|
+
result = Libis::Format::Tool::PdfMerge.run(source, target)
|
52
|
+
|
53
|
+
unless result[:err].empty?
|
54
|
+
error("PdfMerge encountered errors:\n%s", result[:err].join(join("\n")))
|
55
|
+
return nil
|
56
|
+
end
|
57
|
+
|
58
|
+
target
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -1,103 +1,52 @@
|
|
1
|
-
#
|
1
|
+
# encoding: utf-8
|
2
2
|
|
3
3
|
require_relative 'base'
|
4
4
|
|
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'
|
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)
|
22
|
+
return [] unless input_types.include?(format) if format
|
23
|
+
[:PDF, :PDFA]
|
24
|
+
end
|
21
25
|
|
22
|
-
|
26
|
+
def title(v)
|
27
|
+
@options[:title] = v.blank? ? nil : v
|
23
28
|
end
|
24
29
|
|
25
|
-
def
|
26
|
-
|
30
|
+
def author(v)
|
31
|
+
@options[:author] = v.blank? ? nil : v
|
27
32
|
end
|
28
33
|
|
29
|
-
|
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
|
-
|
44
|
-
@options["md_#{k}"] = v
|
45
|
-
end
|
34
|
+
def creator(v)
|
35
|
+
@options[:creator] = v.blank? ? nil : v
|
46
36
|
end
|
47
37
|
|
48
|
-
|
49
|
-
|
50
|
-
def range(selection)
|
51
|
-
@options[:ranges] = selection
|
38
|
+
def keywords(v)
|
39
|
+
@options[:keywords] = v.blank? ? nil : v
|
52
40
|
end
|
53
41
|
|
54
|
-
|
55
|
-
|
56
|
-
# The watermark options are (use symbols):
|
57
|
-
# - text: text to create a watermark from
|
58
|
-
# - file: watermark image to use
|
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] && File.exist?(options[:file])
|
74
|
-
@options['wm_image'] = options[:file]
|
75
|
-
else
|
76
|
-
@options['wm_text'] = (options[:text] || '© LIBIS').split('\n')
|
77
|
-
@options['wm_text_rotation'] = options[:rotation] if options[:rotation]
|
78
|
-
@options['wm_font_size'] = options[:size] if options[:size]
|
79
|
-
end
|
80
|
-
@options['wm_opacity'] = options[:opacity] || '0.3'
|
81
|
-
@options['wm_gap_ratio'] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
|
82
|
-
@options['wm_gap_size'] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
|
42
|
+
def subject(v)
|
43
|
+
@options[:subject] = v.blank? ? nil : v
|
83
44
|
end
|
84
45
|
|
85
|
-
#
|
86
|
-
#
|
87
|
-
|
88
|
-
|
89
|
-
#
|
90
|
-
# - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
|
91
|
-
# - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
|
92
|
-
# - 2 : good quality
|
93
|
-
# - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
|
94
|
-
# - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
|
95
|
-
#
|
96
|
-
# Note that the optimization is intended to be used with PDF's containing high-resolution images.
|
97
|
-
#
|
98
|
-
# @param [Integer] setting quality setting. [0-4]
|
99
|
-
def optimize(setting = 1)
|
100
|
-
@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
|
101
50
|
end
|
102
51
|
|
103
52
|
def convert(source, target, format, opts = {})
|
@@ -105,50 +54,40 @@ module Libis
|
|
105
54
|
|
106
55
|
result = nil
|
107
56
|
|
108
|
-
if (quality = @options.delete('optimize'))
|
109
|
-
result = optimize_pdf(source, target, quality)
|
110
|
-
return nil unless result
|
111
|
-
|
112
|
-
source = result
|
113
|
-
end
|
114
|
-
|
115
57
|
unless @options.empty?
|
116
58
|
result = convert_pdf(source, target)
|
117
59
|
return nil unless result
|
118
|
-
|
119
60
|
source = result
|
120
61
|
end
|
121
62
|
|
122
|
-
|
63
|
+
if format == :PDFA and source
|
64
|
+
result = pdf_to_pdfa(source, target)
|
65
|
+
end
|
123
66
|
|
124
|
-
|
125
|
-
files: [result],
|
126
|
-
converter: self.class.name
|
127
|
-
}
|
128
|
-
end
|
67
|
+
result
|
129
68
|
|
130
|
-
def optimize_pdf(source, target, quality)
|
131
|
-
using_temp(target) do |tmpname|
|
132
|
-
result = Libis::Format::Tool::PdfOptimizer.run(source, tmpname, quality)
|
133
|
-
unless (result[:status]).zero?
|
134
|
-
error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join("\n"))
|
135
|
-
next nil
|
136
|
-
end
|
137
|
-
tmpname
|
138
|
-
end
|
139
69
|
end
|
140
70
|
|
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
|
+
|
141
79
|
def convert_pdf(source, target)
|
80
|
+
|
142
81
|
using_temp(target) do |tmpname|
|
143
82
|
result = Libis::Format::Tool::PdfCopy.run(
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
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
|
152
91
|
)
|
153
92
|
unless result[:err].empty?
|
154
93
|
error("Pdf conversion encountered errors:\n%s", result[:err].join(join("\n")))
|
@@ -156,26 +95,26 @@ module Libis
|
|
156
95
|
end
|
157
96
|
tmpname
|
158
97
|
end
|
98
|
+
|
159
99
|
end
|
160
100
|
|
161
101
|
def pdf_to_pdfa(source, target)
|
102
|
+
|
162
103
|
using_temp(target) do |tmpname|
|
163
104
|
result = Libis::Format::Tool::PdfToPdfa.run source, tmpname
|
164
|
-
|
165
|
-
|
166
|
-
error("Pdf/A conversion encountered errors:\n%s", (result[:command][:out] + result[:command][:err]).join("\n"))
|
105
|
+
if result[:status] != 0
|
106
|
+
error("Pdf/A conversion encountered errors:\n%s", result[:err].join("\n"))
|
167
107
|
next nil
|
168
108
|
else
|
169
|
-
|
170
|
-
if r[:status] != 0
|
171
|
-
error "Pdf/A file failed to validate with following errors:\n%s", (r[:err] || r[:out] || []).join("\n")
|
172
|
-
next nil
|
173
|
-
end
|
109
|
+
warn("Pdf/A conversion warnings:\n%s", result[:err].join("\n")) unless result[:err].empty?
|
174
110
|
end
|
175
111
|
tmpname
|
176
112
|
end
|
113
|
+
|
177
114
|
end
|
115
|
+
|
178
116
|
end
|
117
|
+
|
179
118
|
end
|
180
119
|
end
|
181
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
|