Sha256: c67ad1bd624679c77caa9dedef7e6cd4cf9510172793f1e9bd064a4c90dc84c3

Contents?: true

Size: 1.24 KB

Versions: 10

Compression:

Stored size: 1.24 KB

Contents

require 'os'

require 'libis/tools/extend/string'
require 'libis/tools/logger'
require 'libis/tools/command'

require 'libis/format/config'

module Libis
  module Format
    module Tool

      class PdfSplit
        include ::Libis::Tools::Logger

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

        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_split]
          result = Libis::Tools::Command.run(
              Libis::Format::Config[:java_path],
              '-cp', Libis::Format::Config[:pdf_tool],
              'SplitPdf',
              '--file_input', source,
              '--file_output', 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
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
libis-format-1.0.4 lib/libis/format/tool/pdf_split.rb
libis-format-1.0.2 lib/libis/format/tool/pdf_split.rb
libis-format-1.0.1 lib/libis/format/tool/pdf_split.rb
libis-format-1.0.0 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.74 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.72 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.70 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.69 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.68 lib/libis/format/tool/pdf_split.rb
libis-format-0.9.67 lib/libis/format/tool/pdf_split.rb