20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/libis/format/tool/pdfa_validator.rb', line 20
def run(source)
src_file = File.absolute_path(source)
timeout = Libis::Format::Config[:timeouts][:pdfa_validator]
if (pdfa = Libis::Format::Config[:pdfa_path])
previous_wd = Dir.getwd
Dir.chdir(Dir.tmpdir)
result = Libis::Tools::Command.run(
pdfa,
'--noxml',
'--level', 'B',
'--verb', '0',
src_file,
timeout: timeout,
kill_after: timeout * 2
)
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:status] == 0 && result[:err].empty?
Dir.chdir(previous_wd)
unless result[:out].any? {|line| line =~ /^VLD-\[PASS\]/}
warn "Validator failed to validate the PDF file '%s' against PDF/A-1B constraints:\n%s", source,
result[:out].join("\n")
return false
end
else
jar = File.join(Libis::Format::TOOL_DIR, 'pdfbox', 'preflight-app-1.8.10.jar')
result = Libis::Tools::Command.run(
Libis::Format::Config[:java_path],
'-jar', jar,
src_file,
timeout: timeout,
kill_after: timeout * 2
)
raise RuntimeError, "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
raise RuntimeError, "#{self.class} errors: #{result[:err].join("\n")}" unless result[:err].empty?
unless result[:status] == 0
warn "Validator failed to validate the PDF file '%s' against PDF/A-1B constraints:\n%s", source,
result[:out].join("\n")
return false
end
end
true
end
|