libis-format 0.9.13 → 0.9.15
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f27604dfcb12343adb31e0271fe67c30b5065e89
|
4
|
+
data.tar.gz: ff414f39d8bf27a8656cf7d3e2911df1c8d3cd71
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 28fb1119f9857c7a2bda2907303c6f044f5506eef371886f24b9a229ef1bbdf5a5a98ed82289b3eedbd590b0de55d8c9eb08f02ced77a2ef5bdcab85d9b4361c
|
7
|
+
data.tar.gz: cdca98eefb60e202e0dfa5c9ed6d16e9c63e5ba1127907cd34bf8b198a9b1628b340482fe6bc20c753659c1f9ea6e8842aad5016abc0dfc596d11bfa421cbb7e
|
@@ -6,7 +6,7 @@ require 'libis/format/identifier'
|
|
6
6
|
require 'mini_magick'
|
7
7
|
require 'fileutils'
|
8
8
|
|
9
|
-
MiniMagick.logger.level = ::Logger::
|
9
|
+
MiniMagick.logger.level = ::Logger::ERROR
|
10
10
|
|
11
11
|
module Libis
|
12
12
|
module Format
|
@@ -88,6 +88,7 @@ module Libis
|
|
88
88
|
# noinspection RubyResolve
|
89
89
|
MiniMagick::Tool::Convert.new do |convert|
|
90
90
|
# noinspection RubyLiteralArrayInspection
|
91
|
+
convert.quiet
|
91
92
|
convert.background 'transparent'
|
92
93
|
convert.size('2000x2000')
|
93
94
|
convert.gravity 'Center'
|
@@ -5,6 +5,7 @@ require_relative 'base'
|
|
5
5
|
require 'libis/tools/extend/hash'
|
6
6
|
require 'libis/format/pdf_copy'
|
7
7
|
require 'libis/format/pdf_to_pdfa'
|
8
|
+
require 'libis/format/pdf_optimizer'
|
8
9
|
|
9
10
|
module Libis
|
10
11
|
module Format
|
@@ -78,12 +79,37 @@ module Libis
|
|
78
79
|
@options['wm_gap_size'] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
|
79
80
|
end
|
80
81
|
|
82
|
+
# Optimize the PDF
|
83
|
+
#
|
84
|
+
# This reduces the graphics quality to a level in order to limit file size. This option relies on the
|
85
|
+
# presence of ghostscript and takes one argument: the quality level. It should be one of:
|
86
|
+
#
|
87
|
+
# - 0 : lowest quality (Acrobat Distiller 'Screen Optimized' equivalent)
|
88
|
+
# - 1 : medium quality (Acrobat Distiller 'eBook' equivalent)
|
89
|
+
# - 2 : good quality
|
90
|
+
# - 3 : high quality (Acrobat Distiller 'Print Optimized' equivalent)
|
91
|
+
# - 4 : highest quality (Acrobat Distiller 'Prepress Optimized' equivalent)
|
92
|
+
#
|
93
|
+
# Note that the optimization is intended to be used with PDF's containing high-resolution images.
|
94
|
+
#
|
95
|
+
# @param [Integer] setting quality setting. [0-4]
|
96
|
+
def optimize(setting = 1)
|
97
|
+
@options['optimize'] = %w(screen ebook default printer prepress)[setting] if (0..4) === setting
|
98
|
+
end
|
99
|
+
|
81
100
|
def convert(source, target, format, opts = {})
|
82
101
|
super
|
83
102
|
|
84
103
|
result = nil
|
85
104
|
|
86
105
|
unless @options.empty?
|
106
|
+
|
107
|
+
if (quality = @options.delete('optimize'))
|
108
|
+
result = optimize_pdf(source, target, quality)
|
109
|
+
return nil unless result
|
110
|
+
source = result
|
111
|
+
end
|
112
|
+
|
87
113
|
result = convert_pdf(source, target)
|
88
114
|
return nil unless result
|
89
115
|
source = result
|
@@ -97,6 +123,17 @@ module Libis
|
|
97
123
|
|
98
124
|
end
|
99
125
|
|
126
|
+
def optimize_pdf(source, target, quality)
|
127
|
+
|
128
|
+
using_temp(target) do |tmpname|
|
129
|
+
result = Libis::Format::PdfOptimizer.run(source, tmpname, quality)
|
130
|
+
unless result[:err].empty?
|
131
|
+
error("Pdf optimization encountered errors:\n%s", (result[:err] + result[:out]).join('\n'))
|
132
|
+
next nil
|
133
|
+
end
|
134
|
+
tmpname
|
135
|
+
end
|
136
|
+
end
|
100
137
|
|
101
138
|
def convert_pdf(source, target)
|
102
139
|
|
@@ -110,9 +147,9 @@ module Libis
|
|
110
147
|
["--#{k}", (v.is_a?(Array) ? v : v.to_s)]
|
111
148
|
end }.flatten
|
112
149
|
)
|
113
|
-
result[:err].empty?
|
150
|
+
unless result[:err].empty?
|
114
151
|
error("Pdf conversion encountered errors:\n%s", result[:err].join('\n'))
|
115
|
-
nil
|
152
|
+
next nil
|
116
153
|
end
|
117
154
|
tmpname
|
118
155
|
end
|
@@ -123,9 +160,9 @@ module Libis
|
|
123
160
|
|
124
161
|
using_temp(target) do |tmpname|
|
125
162
|
result = Libis::Format::PdfToPdfa.run source, tmpname
|
126
|
-
result[:status] == 0
|
163
|
+
unless result[:status] == 0
|
127
164
|
error("Pdf/A conversion encountered errors:\n%s", result[:err].join('\n'))
|
128
|
-
nil
|
165
|
+
next nil
|
129
166
|
end
|
130
167
|
tmpname
|
131
168
|
end
|
@@ -0,0 +1,36 @@
|
|
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 PdfOptimizer
|
13
|
+
include ::Libis::Tools::Logger
|
14
|
+
|
15
|
+
def self.run(source, target, quality)
|
16
|
+
self.new.run source, target, quality
|
17
|
+
end
|
18
|
+
|
19
|
+
def run(source, target, quality)
|
20
|
+
|
21
|
+
Libis::Tools::Command.run(
|
22
|
+
'gs',
|
23
|
+
'-sDEVICE=prdfwrite',
|
24
|
+
'-dCompatibilityLevel=1.4',
|
25
|
+
"dPDFSETTINGS=/#{quality}",
|
26
|
+
'-dNOPAUSE',
|
27
|
+
'-dBATCH',
|
28
|
+
"-sOutputFile='#{target}'",
|
29
|
+
"'#{source}'"
|
30
|
+
)
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
data/lib/libis/format/version.rb
CHANGED
data/lib/libis/format.rb
CHANGED
@@ -5,11 +5,14 @@ module Libis
|
|
5
5
|
autoload :Config, 'libis/format/config'
|
6
6
|
autoload :TypeDatabase, 'libis/format/type_database'
|
7
7
|
autoload :Identifier, 'libis/format/identifier'
|
8
|
+
|
8
9
|
autoload :Fido, 'libis/format/fido'
|
9
10
|
autoload :Droid, 'libis/format/droid'
|
11
|
+
|
10
12
|
autoload :OfficeToPdf, 'libis/format/office_to_pdf'
|
11
13
|
autoload :PdfCopy, 'libis/format/pdf_copy'
|
12
14
|
autoload :PdfMerge, 'libis/format/pdf_merge'
|
15
|
+
autoload :PdfOptimizer, 'libis/format/pdf_optimizer'
|
13
16
|
autoload :PdfSplit, 'libis/format/pdf_split'
|
14
17
|
autoload :PdfToPdfa, 'libis/format/pdf_to_pdfa'
|
15
18
|
autoload :PdfaValidator, 'libis/format/pdfa_validator'
|
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.15
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kris Dekeyser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,6 +166,7 @@ files:
|
|
166
166
|
- lib/libis/format/office_to_pdf.rb
|
167
167
|
- lib/libis/format/pdf_copy.rb
|
168
168
|
- lib/libis/format/pdf_merge.rb
|
169
|
+
- lib/libis/format/pdf_optimizer.rb
|
169
170
|
- lib/libis/format/pdf_split.rb
|
170
171
|
- lib/libis/format/pdf_to_pdfa.rb
|
171
172
|
- lib/libis/format/pdfa_validator.rb
|