Class: Libis::Format::Tool::PdfMerge

Inherits:
Object
  • Object
show all
Includes:
Tools::Logger
Defined in:
lib/libis/format/tool/pdf_merge.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_merge.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_merge.rb', line 20

def run(source, target, options = [])
  source = [source] unless source.is_a?(Array)

  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_merge]
  result = Libis::Tools::Command.run(
      Libis::Format::Config[:java_path],
      '-cp', Libis::Format::Config[:pdf_tool],
      'MergePdf',
      '--file_output', target,
      *options,
      *source,
      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?

end