libis-format 0.9.5-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +2 -0
- data/.gitignore +18 -0
- data/.travis.yml +41 -0
- data/Gemfile +5 -0
- data/LICENSE.txt +22 -0
- data/README.md +39 -0
- data/Rakefile +8 -0
- data/bin/droid +15 -0
- data/bin/fido +12 -0
- data/bin/pdf_copy +13 -0
- data/data/ISOcoated_v2_eci.icc +0 -0
- data/data/PDFA_def.ps +40 -0
- data/data/ead.xsd +2728 -0
- data/data/eciRGB_v2.icc +0 -0
- data/data/lias_formats.xml +106 -0
- data/data/types.yml +217 -0
- data/lib/libis/format/config.rb +35 -0
- data/lib/libis/format/converter/base.rb +101 -0
- data/lib/libis/format/converter/chain.rb +167 -0
- data/lib/libis/format/converter/image_converter.rb +214 -0
- data/lib/libis/format/converter/office_converter.rb +50 -0
- data/lib/libis/format/converter/pdf_converter.rb +139 -0
- data/lib/libis/format/converter/repository.rb +98 -0
- data/lib/libis/format/converter.rb +11 -0
- data/lib/libis/format/droid.rb +45 -0
- data/lib/libis/format/fido.rb +102 -0
- data/lib/libis/format/identifier.rb +189 -0
- data/lib/libis/format/office_to_pdf.rb +52 -0
- data/lib/libis/format/pdf_copy.rb +40 -0
- 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 +76 -0
- data/lib/libis/format/pdfa_validator.rb +61 -0
- data/lib/libis/format/type_database.rb +170 -0
- data/lib/libis/format/version.rb +5 -0
- data/lib/libis/format.rb +23 -0
- data/lib/libis-format.rb +1 -0
- data/libis-format.gemspec +34 -0
- data/spec/converter_spec.rb +212 -0
- data/spec/data/Cevennes2.bmp +0 -0
- data/spec/data/Cevennes2.jp2 +0 -0
- data/spec/data/Cevennes2.ppm +22492 -0
- data/spec/data/test-ead.xml +392 -0
- data/spec/data/test-jpg.tif +0 -0
- data/spec/data/test-lzw.tif +0 -0
- data/spec/data/test-options.jpg +0 -0
- data/spec/data/test.bmp +0 -0
- data/spec/data/test.doc +0 -0
- data/spec/data/test.docx +0 -0
- data/spec/data/test.gif +0 -0
- data/spec/data/test.jpg +0 -0
- data/spec/data/test.ods +0 -0
- data/spec/data/test.odt +0 -0
- data/spec/data/test.pdf +0 -0
- data/spec/data/test.pdf.tif +0 -0
- data/spec/data/test.png +0 -0
- data/spec/data/test.ps +8631 -0
- data/spec/data/test.psd +0 -0
- data/spec/data/test.rtf +1455 -0
- data/spec/data/test.tif +0 -0
- data/spec/data/test.txt +12 -0
- data/spec/data/test.xcf +0 -0
- data/spec/data/test.xls +0 -0
- data/spec/data/test.xlsx +0 -0
- data/spec/data/test.xml +4 -0
- data/spec/data/test_pdfa.pdf +0 -0
- data/spec/identifier_spec.rb +60 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/test_types.yml +12 -0
- data/spec/type_database_spec.rb +140 -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
- data/tools/droid/DROID_SignatureFile_V82.xml +32681 -0
- data/tools/droid/container-signature-20150307.xml +2235 -0
- data/tools/droid/droid-command-line-6.1.5.jar +0 -0
- data/tools/droid/droid.bat +154 -0
- data/tools/droid/droid.sh +138 -0
- data/tools/droid/lib/XmlSchema-1.4.7.jar +0 -0
- data/tools/droid/lib/activation-1.1.jar +0 -0
- data/tools/droid/lib/antlr-2.7.7.jar +0 -0
- data/tools/droid/lib/antlr-3.2.jar +0 -0
- data/tools/droid/lib/antlr-runtime-3.2.jar +0 -0
- data/tools/droid/lib/aopalliance-1.0.jar +0 -0
- data/tools/droid/lib/asm-2.2.3.jar +0 -0
- data/tools/droid/lib/aspectjrt-1.7.2.jar +0 -0
- data/tools/droid/lib/aspectjweaver-1.7.2.jar +0 -0
- data/tools/droid/lib/bcmail-jdk14-138.jar +0 -0
- data/tools/droid/lib/bcprov-jdk14-138.jar +0 -0
- data/tools/droid/lib/beansbinding-1.2.1.jar +0 -0
- data/tools/droid/lib/byteseek-1.1.1.jar +0 -0
- data/tools/droid/lib/cglib-nodep-2.2.2.jar +0 -0
- data/tools/droid/lib/classmate-1.0.0.jar +0 -0
- data/tools/droid/lib/commons-cli-1.2.jar +0 -0
- data/tools/droid/lib/commons-codec-1.4.jar +0 -0
- data/tools/droid/lib/commons-collections-3.2.1.jar +0 -0
- data/tools/droid/lib/commons-compress-1.4.1.jar +0 -0
- data/tools/droid/lib/commons-configuration-1.8.jar +0 -0
- data/tools/droid/lib/commons-dbcp-1.4.jar +0 -0
- data/tools/droid/lib/commons-httpclient-3.1.jar +0 -0
- data/tools/droid/lib/commons-io-2.4.jar +0 -0
- data/tools/droid/lib/commons-lang-2.6.jar +0 -0
- data/tools/droid/lib/commons-logging-1.1.1.jar +0 -0
- data/tools/droid/lib/commons-pool-1.5.4.jar +0 -0
- data/tools/droid/lib/cxf-api-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-common-schemas-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-common-utilities-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-bindings-http-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-bindings-soap-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-bindings-xml-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-core-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-databinding-jaxb-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-frontend-jaxws-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-frontend-simple-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-transports-http-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-rt-ws-addr-2.2.12.jar +0 -0
- data/tools/droid/lib/cxf-tools-common-2.2.12.jar +0 -0
- data/tools/droid/lib/de.huxhorn.lilith.3rdparty.flyingsaucer.core-renderer-8RC1.jar +0 -0
- data/tools/droid/lib/derby-10.10.2.0.jar +0 -0
- data/tools/droid/lib/dom4j-1.6.1.jar +0 -0
- data/tools/droid/lib/droid-container-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-core-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-core-interfaces-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-export-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-export-interfaces-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-help-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-report-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-report-interfaces-6.1.5.jar +0 -0
- data/tools/droid/lib/droid-results-6.1.5.jar +0 -0
- data/tools/droid/lib/ejb3-persistence-1.0.2.GA.jar +0 -0
- data/tools/droid/lib/geronimo-activation_1.1_spec-1.0.2.jar +0 -0
- data/tools/droid/lib/geronimo-annotation_1.0_spec-1.1.1.jar +0 -0
- data/tools/droid/lib/geronimo-javamail_1.4_spec-1.6.jar +0 -0
- data/tools/droid/lib/geronimo-jaxws_2.1_spec-1.0.jar +0 -0
- data/tools/droid/lib/geronimo-stax-api_1.0_spec-1.0.1.jar +0 -0
- data/tools/droid/lib/geronimo-ws-metadata_2.0_spec-1.1.2.jar +0 -0
- data/tools/droid/lib/hibernate-commons-annotations-4.0.4.Final.jar +0 -0
- data/tools/droid/lib/hibernate-core-4.3.5.Final.jar +0 -0
- data/tools/droid/lib/hibernate-entitymanager-4.3.5.Final.jar +0 -0
- data/tools/droid/lib/hibernate-jpa-2.1-api-1.0.0.Final.jar +0 -0
- data/tools/droid/lib/hibernate-validator-5.1.0.Final.jar +0 -0
- data/tools/droid/lib/itext-2.0.8.jar +0 -0
- data/tools/droid/lib/jandex-1.1.0.Final.jar +0 -0
- data/tools/droid/lib/javahelp-2.0.05.jar +0 -0
- data/tools/droid/lib/javassist-3.18.1-GA.jar +0 -0
- data/tools/droid/lib/jaxb-api-2.1.jar +0 -0
- data/tools/droid/lib/jaxb-impl-2.1.13.jar +0 -0
- data/tools/droid/lib/jboss-logging-3.1.3.GA.jar +0 -0
- data/tools/droid/lib/jboss-logging-annotations-1.2.0.Beta1.jar +0 -0
- data/tools/droid/lib/jboss-transaction-api_1.2_spec-1.0.0.Final.jar +0 -0
- data/tools/droid/lib/joda-time-1.6.2.jar +0 -0
- data/tools/droid/lib/jra-1.0-alpha-4.jar +0 -0
- data/tools/droid/lib/jta-1.1.jar +0 -0
- data/tools/droid/lib/log4j-1.2.13.jar +0 -0
- data/tools/droid/lib/neethi-2.0.4.jar +0 -0
- data/tools/droid/lib/opencsv-2.3.jar +0 -0
- data/tools/droid/lib/org-netbeans-swing-outline-7.2.jar +0 -0
- data/tools/droid/lib/org-openide-util-7.2.jar +0 -0
- data/tools/droid/lib/org-openide-util-lookup-7.2.jar +0 -0
- data/tools/droid/lib/poi-3.7.jar +0 -0
- data/tools/droid/lib/saaj-api-1.3.jar +0 -0
- data/tools/droid/lib/saaj-impl-1.3.2.jar +0 -0
- data/tools/droid/lib/slf4j-api-1.4.2.jar +0 -0
- data/tools/droid/lib/slf4j-log4j12-1.4.2.jar +0 -0
- data/tools/droid/lib/spring-aop-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-beans-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-context-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-core-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-expression-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-jdbc-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-orm-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-tx-4.0.3.RELEASE.jar +0 -0
- data/tools/droid/lib/spring-web-2.5.6.jar +0 -0
- data/tools/droid/lib/stax-api-1.0-2.jar +0 -0
- data/tools/droid/lib/stringtemplate-3.2.jar +0 -0
- data/tools/droid/lib/truezip-6.8.4.jar +0 -0
- data/tools/droid/lib/validation-api-1.1.0.Final.jar +0 -0
- data/tools/droid/lib/wsdl4j-1.6.2.jar +0 -0
- data/tools/droid/lib/wstx-asl-3.2.9.jar +0 -0
- data/tools/droid/lib/xercesImpl-2.9.1.jar +0 -0
- data/tools/droid/lib/xml-apis-1.3.04.jar +0 -0
- data/tools/droid/lib/xml-resolver-1.2.jar +0 -0
- data/tools/droid/lib/xz-1.0.jar +0 -0
- data/tools/fido/__init__.py +0 -0
- data/tools/fido/argparselocal.py +2355 -0
- data/tools/fido/conf/DROID_SignatureFile-v81.xml +2 -0
- data/tools/fido/conf/container-signature-20150307.xml +2238 -0
- data/tools/fido/conf/dc.xsd +119 -0
- data/tools/fido/conf/dcmitype.xsd +53 -0
- data/tools/fido/conf/dcterms.xsd +383 -0
- data/tools/fido/conf/fido-formats.xsd +173 -0
- data/tools/fido/conf/format_extension_template.xml +105 -0
- data/tools/fido/conf/format_extensions.xml +498 -0
- data/tools/fido/conf/formats-v81.xml +38355 -0
- data/tools/fido/conf/pronom-xml-v81.zip +0 -0
- data/tools/fido/conf/versions.xml +8 -0
- data/tools/fido/fido.bat +4 -0
- data/tools/fido/fido.py +854 -0
- data/tools/fido/fido.sh +5 -0
- data/tools/fido/prepare.py +616 -0
- data/tools/fido/pronomutils.py +115 -0
- data/tools/fido/toxml.py +52 -0
- data/tools/fido/update_signatures.py +171 -0
- data/tools/pdfbox/pdfbox-app-1.8.10.jar +0 -0
- data/tools/pdfbox/preflight-app-1.8.10.jar +0 -0
- metadata +396 -0
@@ -0,0 +1,214 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
require 'libis/format/identifier'
|
5
|
+
|
6
|
+
require 'mini_magick'
|
7
|
+
require 'fileutils'
|
8
|
+
|
9
|
+
MiniMagick.configure do |config|
|
10
|
+
config.debug = false
|
11
|
+
end
|
12
|
+
|
13
|
+
module Libis
|
14
|
+
module Format
|
15
|
+
module Converter
|
16
|
+
|
17
|
+
class ImageConverter < Libis::Format::Converter::Base
|
18
|
+
|
19
|
+
def self.input_types(format = nil)
|
20
|
+
[:TIFF, :JPG, :PNG, :BMP, :GIF, :JP2, :PDF]
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.output_types(_ = nil)
|
24
|
+
[:TIFF, :JPG, :PNG, :BMP, :GIF, :JP2, :PDF]
|
25
|
+
end
|
26
|
+
|
27
|
+
def initialize
|
28
|
+
@wm_image = nil
|
29
|
+
super
|
30
|
+
end
|
31
|
+
|
32
|
+
def image_convert(_)
|
33
|
+
#force usage of this converter
|
34
|
+
end
|
35
|
+
|
36
|
+
def scale(percent)
|
37
|
+
@options[:scale] = percent
|
38
|
+
end
|
39
|
+
|
40
|
+
def resize(geometry)
|
41
|
+
@options[:resize] = geometry
|
42
|
+
end
|
43
|
+
|
44
|
+
def quality(value)
|
45
|
+
@options[:quality] = value
|
46
|
+
end
|
47
|
+
|
48
|
+
def dpi(value)
|
49
|
+
@options[:density] = value
|
50
|
+
end
|
51
|
+
|
52
|
+
def resample(value)
|
53
|
+
@options[:density] = value
|
54
|
+
end
|
55
|
+
|
56
|
+
def flatten
|
57
|
+
@flags[:flatten] = true
|
58
|
+
end
|
59
|
+
|
60
|
+
def colorspace(value)
|
61
|
+
@options[:colorspace] = value
|
62
|
+
end
|
63
|
+
|
64
|
+
# Create or use a watermark image.
|
65
|
+
#
|
66
|
+
# The watermark options are:
|
67
|
+
# - file: watermark image to use
|
68
|
+
# - text: text to create a watermark from
|
69
|
+
# - rotation: rotation of the watermark text (counter clockwise in degrees; integer number) - default 30
|
70
|
+
# - size: size of the watermark (integer > 0, 1/n of image size) - default 4
|
71
|
+
# - opacity: opacity of the watermark (fraction 0.0 - 1.0) - default 0.3
|
72
|
+
# - gap: size of the gap between watermark instances. Fractions as percentage of widht/height. - default 0.2
|
73
|
+
# If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
|
74
|
+
# file will be created or overwritten with a newly created watermark image.
|
75
|
+
#
|
76
|
+
# The created watermark file will be a PNG image with transparent background containing the supplied text
|
77
|
+
# slanted by 30 degrees counter-clockwise.
|
78
|
+
#
|
79
|
+
# @param [Hash] options Hash of options for watermark creation.
|
80
|
+
def watermark(options = {})
|
81
|
+
text = options[:text] || '© LIBIS'
|
82
|
+
image = options[:file] || (Dir::Tmpname.create(%w(wm_image .png)) { |_|})
|
83
|
+
@wm_size = (options[:size] || '4').to_i
|
84
|
+
@wm_opacity = ((options[:opacity] || 0.1).to_f * 100).to_i
|
85
|
+
@wm_composition = options[:composition] || 'modulate'
|
86
|
+
gap = ((options[:gap] || 0.2).to_f * 100).to_i
|
87
|
+
rotation = 360 - (options[:rotation] || 30).to_i
|
88
|
+
@wm_image = MiniMagick::Image.new(image)
|
89
|
+
unless @wm_image.valid?
|
90
|
+
# noinspection RubyResolve
|
91
|
+
MiniMagick::Tool::Convert.new do |convert|
|
92
|
+
# noinspection RubyLiteralArrayInspection
|
93
|
+
convert.background 'transparent'
|
94
|
+
convert.size('2000x2000')
|
95
|
+
convert.gravity 'Center'
|
96
|
+
convert.font('Helvetica').fill('black').pointsize(72) #.stroke('black').strokewidth(1)
|
97
|
+
convert << "label:#{text}"
|
98
|
+
convert.rotate rotation
|
99
|
+
convert.trim.repage.+
|
100
|
+
convert.bordercolor('transparent').border("#{gap}%")
|
101
|
+
convert << image
|
102
|
+
end
|
103
|
+
if options[:file]
|
104
|
+
@wm_image = MiniMagick::Image.new(image)
|
105
|
+
else
|
106
|
+
@wm_image = MiniMagick::Image.open(image)
|
107
|
+
File.delete(image)
|
108
|
+
end
|
109
|
+
# noinspection RubyResolve
|
110
|
+
unless @wm_image.valid?
|
111
|
+
error "Problem creating watermark image '#{image}'."
|
112
|
+
@wm_image = nil
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def convert(source, target, format, opts = {})
|
118
|
+
super
|
119
|
+
|
120
|
+
FileUtils.mkpath(File.dirname(target))
|
121
|
+
|
122
|
+
if source.is_a? Array
|
123
|
+
sources = source
|
124
|
+
|
125
|
+
unless [:PDF, :TIFF, :GIF, :PBM, :PGM, :PPM].include? format
|
126
|
+
error 'Can ony assemble multiple images into multi-page/layer format'
|
127
|
+
return nil
|
128
|
+
end
|
129
|
+
|
130
|
+
assemble_and_convert(sources, target, format)
|
131
|
+
|
132
|
+
elsif File.directory?(source)
|
133
|
+
sources = Dir[File.join(source, '**', '*')].reject { |p| File.directory? p }
|
134
|
+
|
135
|
+
unless [:TIFF, :PDF].include? format
|
136
|
+
error 'Can ony assemble multiple images into multi-page/layer format'
|
137
|
+
return nil
|
138
|
+
end
|
139
|
+
|
140
|
+
assemble_and_convert(sources, target, format)
|
141
|
+
|
142
|
+
else
|
143
|
+
|
144
|
+
image = MiniMagick::Image.new(source)
|
145
|
+
|
146
|
+
if image.pages.size > 1
|
147
|
+
assemble_and_convert(image.pages.map {|page| page.path}, target, format)
|
148
|
+
else
|
149
|
+
convert_image(source, target, format)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
target
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
def assemble_and_convert(sources, target, format)
|
158
|
+
converted_pages = sources.inject([]) do |list, path|
|
159
|
+
converted = Tempfile.new(['page-', ".#{Libis::Format::TypeDatabase.type_extentions(format).first}"])
|
160
|
+
convert_image(path, converted.path, format)
|
161
|
+
list << converted
|
162
|
+
end
|
163
|
+
MiniMagick::Tool::Convert.new do |b|
|
164
|
+
converted_pages.each { |page| b << page.path }
|
165
|
+
b << target
|
166
|
+
end
|
167
|
+
converted_pages.each do |temp_file|
|
168
|
+
temp_file.close
|
169
|
+
temp_file.unlink
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
protected
|
174
|
+
|
175
|
+
def convert_image(source, target, format)
|
176
|
+
|
177
|
+
image = MiniMagick::Image.new(source)
|
178
|
+
|
179
|
+
MiniMagick::Tool::Convert.new do |convert|
|
180
|
+
if @wm_image
|
181
|
+
convert << @wm_image.path
|
182
|
+
convert.filter('Lagrange')
|
183
|
+
convert.resize("#{image.width / @wm_size}x#{image.height / @wm_size}").write('mpr:watermark').delete.+
|
184
|
+
end
|
185
|
+
|
186
|
+
convert << source
|
187
|
+
convert.flatten if format == :JPG
|
188
|
+
if @wm_image
|
189
|
+
# noinspection RubyResolve
|
190
|
+
convert.stack do |stack|
|
191
|
+
stack.size("#{image.width}x#{image.height}")
|
192
|
+
stack << 'xc:transparent'
|
193
|
+
stack.tile('mpr:watermark')
|
194
|
+
stack.draw "rectangle 0,0,#{image.width},#{image.height}"
|
195
|
+
end
|
196
|
+
convert.compose(@wm_composition).define("compose:args=#{@wm_opacity}").composite
|
197
|
+
end
|
198
|
+
|
199
|
+
@options.each { |o, v| convert.send(o, v) }
|
200
|
+
@flags.each { |f, v| v.is_a?(FalseClass) ? convert.send(f).+ : convert.send(f) }
|
201
|
+
|
202
|
+
convert.format(format)
|
203
|
+
convert << target
|
204
|
+
end
|
205
|
+
|
206
|
+
target
|
207
|
+
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
end
|
214
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/format/office_to_pdf'
|
6
|
+
require 'libis/format/type_database'
|
7
|
+
|
8
|
+
module Libis
|
9
|
+
module Format
|
10
|
+
module Converter
|
11
|
+
|
12
|
+
class OfficeConverter < Libis::Format::Converter::Base
|
13
|
+
|
14
|
+
def self.input_types(_ = nil)
|
15
|
+
[
|
16
|
+
:TXT,
|
17
|
+
:RTF,
|
18
|
+
:HTML,
|
19
|
+
:MSDOC,
|
20
|
+
:MSXLS,
|
21
|
+
:MSPPT,
|
22
|
+
:MSDOCX,
|
23
|
+
:MSXLSX,
|
24
|
+
:MSPPTX,
|
25
|
+
:WORDPERFECT,
|
26
|
+
]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.output_types(_ = nil)
|
30
|
+
[:PDF]
|
31
|
+
end
|
32
|
+
|
33
|
+
def office_convert(_)
|
34
|
+
#force usage of this converter
|
35
|
+
end
|
36
|
+
|
37
|
+
def convert(source, target, format, opts = {})
|
38
|
+
super
|
39
|
+
|
40
|
+
return nil unless OfficeToPdf.run(source, target)
|
41
|
+
|
42
|
+
target
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require_relative 'base'
|
4
|
+
|
5
|
+
require 'libis/tools/extend/hash'
|
6
|
+
require 'libis/format/pdf_copy'
|
7
|
+
require 'libis/format/pdf_to_pdfa'
|
8
|
+
|
9
|
+
module Libis
|
10
|
+
module Format
|
11
|
+
module Converter
|
12
|
+
|
13
|
+
class PdfConverter < Libis::Format::Converter::Base
|
14
|
+
|
15
|
+
def self.input_types(_ = nil)
|
16
|
+
[:PDF]
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.output_types(_ = nil)
|
20
|
+
[:PDF, :PDFA]
|
21
|
+
end
|
22
|
+
|
23
|
+
def pdf_convert(_)
|
24
|
+
#force usage of this converter
|
25
|
+
end
|
26
|
+
|
27
|
+
# Set metadata for Pdf file
|
28
|
+
#
|
29
|
+
# valid metadata keys are):
|
30
|
+
# - title
|
31
|
+
# - author
|
32
|
+
# - creator
|
33
|
+
# - keywords
|
34
|
+
# - subject
|
35
|
+
#
|
36
|
+
# @param [Hash] values list of metadata values to set
|
37
|
+
def metadata(values = {})
|
38
|
+
values.key_strings_to_symbols!
|
39
|
+
values.each do |k, v|
|
40
|
+
next unless [:title, :author, :creator, :keywords, :subject].include?(k)
|
41
|
+
@options["md_#{k}"] = v
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# Select a partial list of pages
|
46
|
+
# @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][odd][e][even]start-end
|
47
|
+
def range(selection)
|
48
|
+
@options[:ranges] = selection
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create or use a watermark image.
|
52
|
+
#
|
53
|
+
# The watermark options are (use symbols):
|
54
|
+
# - text: text to create a watermark from
|
55
|
+
# - file: watermark image to use
|
56
|
+
# - rotation: rotation of the watermark text (in degrees; integer number)
|
57
|
+
# - size: font size of the watermark text
|
58
|
+
# - opacity: opacity of the watermark (fraction 0.0 - 1.0)
|
59
|
+
# - gap: size of the gap between watermark instances. Integer value is absolute size in points (1/72 inch). Fractions are percentage of widht/height.
|
60
|
+
# If both options are given, the file will be used as-is if it exists and is a valid image file. Otherwise the
|
61
|
+
# file will be created or overwritten with a newly created watermark image.
|
62
|
+
#
|
63
|
+
# The created watermark file will be a PNG image with transparent background containing the supplied text
|
64
|
+
# slanted by 30 degrees counter-clockwise.
|
65
|
+
#
|
66
|
+
# @param [Hash] options Hash of options for watermark creation.
|
67
|
+
def watermark(options = {})
|
68
|
+
options.key_strings_to_symbols!
|
69
|
+
if options[:file] && File.exist?(options[:file])
|
70
|
+
@options['wm_image'] = options[:file]
|
71
|
+
else
|
72
|
+
@options['wm_text'] = (options[:text] || '© LIBIS').split('\n')
|
73
|
+
@options['wm_text_rotation'] = options[:rotation] if options[:rotation]
|
74
|
+
@options['wm_font_size'] = options[:size] if options[:size]
|
75
|
+
end
|
76
|
+
@options['wm_opacity'] = options[:opacity] || '0.3'
|
77
|
+
@options['wm_gap_ratio'] = options[:gap] if options[:gap].to_s =~ /^\s*(0+\.\d+|1\.0+)\s*$/
|
78
|
+
@options['wm_gap_size'] = options[:gap] if options[:gap].to_s =~ /^\s*\d+\s*$/
|
79
|
+
end
|
80
|
+
|
81
|
+
def convert(source, target, format, opts = {})
|
82
|
+
super
|
83
|
+
|
84
|
+
result = nil
|
85
|
+
|
86
|
+
unless @options.empty?
|
87
|
+
result = convert_pdf(source, target)
|
88
|
+
return nil unless result
|
89
|
+
source = result
|
90
|
+
end
|
91
|
+
|
92
|
+
if format == :PDFA and source
|
93
|
+
result = pdf_to_pdfa(source, target)
|
94
|
+
end
|
95
|
+
|
96
|
+
result
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
|
101
|
+
def convert_pdf(source, target)
|
102
|
+
|
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
|
119
|
+
|
120
|
+
end
|
121
|
+
|
122
|
+
def pdf_to_pdfa(source, target)
|
123
|
+
|
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
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require 'set'
|
4
|
+
require 'singleton'
|
5
|
+
|
6
|
+
require 'libis/tools/logger'
|
7
|
+
require 'libis/format/config'
|
8
|
+
|
9
|
+
require_relative 'chain'
|
10
|
+
|
11
|
+
module Libis
|
12
|
+
module Format
|
13
|
+
module Converter
|
14
|
+
|
15
|
+
class Repository
|
16
|
+
include Singleton
|
17
|
+
include ::Libis::Tools::Logger
|
18
|
+
|
19
|
+
attr_reader :converters
|
20
|
+
attr_accessor :converters_glob
|
21
|
+
|
22
|
+
def initialize
|
23
|
+
@converters = Set.new
|
24
|
+
@converters_glob = File.join(File.dirname(__FILE__), '*_converter.rb')
|
25
|
+
end
|
26
|
+
|
27
|
+
def Repository.register(converter_class)
|
28
|
+
instance.converters.add? converter_class
|
29
|
+
end
|
30
|
+
|
31
|
+
def Repository.get_converters
|
32
|
+
instance.get_converters
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_converters
|
36
|
+
if converters.empty?
|
37
|
+
Dir.glob(converters_glob).each do |filename|
|
38
|
+
# noinspection RubyResolve
|
39
|
+
require File.expand_path(filename)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
converters
|
43
|
+
end
|
44
|
+
|
45
|
+
def Repository.get_converter_chain(src_type, tgt_type, operations = {})
|
46
|
+
instance.get_converter_chain src_type, tgt_type, operations
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_converter_chain(src_type, tgt_type, operations = {})
|
50
|
+
msg = "conversion from #{src_type.to_s} to #{tgt_type.to_s}"
|
51
|
+
chain_list = find_chains src_type, tgt_type, operations
|
52
|
+
# if chain_list.length > 1
|
53
|
+
# warn "Found more than one conversion chain for #{msg}. Picking the first one."
|
54
|
+
# end
|
55
|
+
if chain_list.empty?
|
56
|
+
error "No conversion chain found for #{msg}"
|
57
|
+
return nil
|
58
|
+
end
|
59
|
+
# chain_list.each do |chain|
|
60
|
+
# debug "Matched chain: #{chain}"
|
61
|
+
# end
|
62
|
+
chain_list[0]
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def find_chains(src_type, tgt_type, operations)
|
68
|
+
chain = Libis::Format::Converter::Chain.new(src_type, tgt_type, operations)
|
69
|
+
build_chains(chain)
|
70
|
+
end
|
71
|
+
|
72
|
+
def build_chains(chain)
|
73
|
+
|
74
|
+
found = []
|
75
|
+
chains = [chain]
|
76
|
+
|
77
|
+
# Avoid chains that are too long
|
78
|
+
Libis::Format::Config[:converter_chain_max_level].times do
|
79
|
+
new_chains = []
|
80
|
+
get_converters.each do |converter|
|
81
|
+
new_chains += chains.map { |c| c.append(converter) }.flatten
|
82
|
+
end
|
83
|
+
|
84
|
+
found = new_chains.select { |c| c.valid?}
|
85
|
+
return found unless found.empty?
|
86
|
+
|
87
|
+
chains = new_chains
|
88
|
+
end
|
89
|
+
|
90
|
+
found
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'tempfile'
|
2
|
+
require 'csv'
|
3
|
+
|
4
|
+
require 'libis/tools/extend/string'
|
5
|
+
require 'libis/tools/logger'
|
6
|
+
require 'libis/tools/command'
|
7
|
+
|
8
|
+
require 'libis/format/config'
|
9
|
+
|
10
|
+
module Libis
|
11
|
+
module Format
|
12
|
+
|
13
|
+
class Droid
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
def self.run(file)
|
17
|
+
self.new.run file
|
18
|
+
end
|
19
|
+
|
20
|
+
def run(file)
|
21
|
+
profile = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname(%w'droid .profile', nil)
|
22
|
+
report = File.join Dir.tmpdir, Dir::Tmpname.make_tmpname(%w'droid .csv', nil)
|
23
|
+
result = Libis::Tools::Command.run(
|
24
|
+
Libis::Format::Config[:droid_path],
|
25
|
+
'-a', file.escape_for_string,
|
26
|
+
'-p', profile,
|
27
|
+
'-q',
|
28
|
+
)
|
29
|
+
warn "DROID profile errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
30
|
+
result = Libis::Tools::Command.run(
|
31
|
+
Libis::Format::Config[:droid_path],
|
32
|
+
'-e', report,
|
33
|
+
'-p', profile,
|
34
|
+
'-q'
|
35
|
+
)
|
36
|
+
warn "DROID report errors: #{result[:err].join("\n")}" unless result[:status] == 0
|
37
|
+
File.delete profile
|
38
|
+
result = CSV.read(report , headers: true, header_converters: [:downcase, :symbol])
|
39
|
+
File.delete report
|
40
|
+
result.map{|r|r.to_hash}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'csv'
|
2
|
+
|
3
|
+
require 'libis/tools/extend/string'
|
4
|
+
require 'libis/tools/logger'
|
5
|
+
require 'libis/tools/command'
|
6
|
+
|
7
|
+
require 'libis/format/config'
|
8
|
+
require 'libis/format/type_database'
|
9
|
+
|
10
|
+
module Libis
|
11
|
+
module Format
|
12
|
+
|
13
|
+
class Fido
|
14
|
+
include ::Libis::Tools::Logger
|
15
|
+
|
16
|
+
BAD_MIMETYPES = [nil, '', 'None', 'application/octet-stream']
|
17
|
+
|
18
|
+
def self.run(file, formats = nil)
|
19
|
+
self.new.run file, formats
|
20
|
+
end
|
21
|
+
|
22
|
+
def run(file, xtra_formats = nil)
|
23
|
+
|
24
|
+
fido_results = []
|
25
|
+
|
26
|
+
fmt_list = formats.dup
|
27
|
+
case xtra_formats
|
28
|
+
when Array
|
29
|
+
fmt_list += xtra_formats
|
30
|
+
when String
|
31
|
+
fmt_list << xtra_formats
|
32
|
+
else
|
33
|
+
# do nothing
|
34
|
+
end
|
35
|
+
|
36
|
+
args = []
|
37
|
+
args << '-loadformats' << "#{fmt_list.join(',')}" unless fmt_list.empty?
|
38
|
+
args << "#{file.escape_for_string}"
|
39
|
+
fido = ::Libis::Tools::Command.run(Libis::Format::Config[:fido_path], *args)
|
40
|
+
warn "Fido errors: #{fido[:err].join("\n")}" unless fido[:err].empty?
|
41
|
+
|
42
|
+
keys = [:status, :time, :puid, :format_name, :signature_name, :filesize, :filename, :mimetype, :matchtype]
|
43
|
+
fido_output = CSV.parse(fido[:out].join("\n")).map { |a| Hash[keys.zip(a)] }
|
44
|
+
|
45
|
+
fido_output.each do |x|
|
46
|
+
if x[:status] == 'OK'
|
47
|
+
x[:mimetype] = get_mimetype(x[:puid]) if x[:mimetype] == 'None'
|
48
|
+
next if BAD_MIMETYPES.include? x[:mimetype]
|
49
|
+
x[:score] = 5
|
50
|
+
case x[:matchtype]
|
51
|
+
when 'signature'
|
52
|
+
x[:score] += 5
|
53
|
+
when 'container'
|
54
|
+
typeinfo = ::Libis::Format::TypeDatabase.puid_typeinfo(x[:puid])
|
55
|
+
ext = File.extname(file)
|
56
|
+
x[:score] += 2 if typeinfo and typeinfo[:EXTENSIONS].include?(ext)
|
57
|
+
else
|
58
|
+
# do nothing
|
59
|
+
end
|
60
|
+
fido_results << x
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
fido_results = fido_results.inject({}) do |result, value|
|
65
|
+
result[value[:score]] ||= []
|
66
|
+
result[value[:score]] << value
|
67
|
+
result
|
68
|
+
end
|
69
|
+
|
70
|
+
max_score = fido_results.keys.max
|
71
|
+
|
72
|
+
# Only if we find a single hit of type 'signature' or 'container', we are confident enough to return a result
|
73
|
+
return {} unless max_score and max_score >= 5 && fido_results[max_score].size == 1
|
74
|
+
|
75
|
+
fido_results[max_score].first
|
76
|
+
end
|
77
|
+
|
78
|
+
def self.add_format(f)
|
79
|
+
instance.formats << f
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.formats
|
83
|
+
instance.formats
|
84
|
+
end
|
85
|
+
|
86
|
+
protected
|
87
|
+
|
88
|
+
attr_reader :formats
|
89
|
+
|
90
|
+
def initialize
|
91
|
+
data_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'data'))
|
92
|
+
@formats = [(File.join(data_dir, 'lias_formats.xml'))]
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_mimetype(puid)
|
96
|
+
::Libis::Format::TypeDatabase.puid_typeinfo(puid)[:MIME].first rescue nil
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|