Class: Libis::Format::Tool::PdfSplit

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.installed? ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
22
# File 'lib/libis/format/tool/pdf_split.rb', line 17

def self.installed?
  result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], '-version')
  return false unless (result[:status]).zero?

  File.exist?(Libis::Format::Config[:pdf_tool])
end

.run(source, target, *args) ⇒ Object



24
25
26
# File 'lib/libis/format/tool/pdf_split.rb', line 24

def self.run(source, target, *args)
  new.run source, target, *args
end

Instance Method Details

#run(source, target, *args) ⇒ Object



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
# File 'lib/libis/format/tool/pdf_split.rb', line 28

def run(source, target, *args)
  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_split]
  result = Libis::Tools::Command.run(
    Libis::Format::Config[:java_cmd],
    '-cp', Libis::Format::Config[:pdf_tool],
    'SplitPdf',
    '--file_input', source,
    '--file_output', target,
    *args,
    timeout:,
    kill_after: timeout * 2
  )

  raise "#{self.class} took too long (> #{timeout} seconds) to complete" if result[:timeout]
  raise "#{self.class} errors: #{result[:err].join("\n")}" unless (result[:status]).zero? && result[:err].empty?

  {
    command: result,
    files: [target] # TODO: collect the files
  }
end