Class: Libis::Format::Tool::PdfSelect

Inherits:
Object
  • Object
show all
Includes:
Tools::Logger
Defined in:
lib/libis/format/tool/pdf_select.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(source, target, options = []) ⇒ Object



16
17
18
# File 'lib/libis/format/tool/pdf_select.rb', line 16

def self.run(source, target, options = [])
  self.new.run source, target, options
end

Instance Method Details

#run(source, target, options = []) ⇒ Object

Raises:

  • (RuntimeError)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/libis/format/tool/pdf_select.rb', line 20

def run(source, target, options = [])

  if OS.java?
    # TODO: import library and execute in current VM. For now do exactly as in MRI.
  end

  timeout = Libis::Format::Config[:timeouts][:pdf_select]
  result = Libis::Tools::Command.run(
      Libis::Format::Config[:java_cmd],
      '-jar', Libis::Format::Config[:pdf_tool],
      'select',
      '-i', source,
      '-o', target,
      *options,
      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?

  result
end