Sha256: 0145ff8e3ca323ed4d2b433c15c1895ba14799ebaca42742b2e3f00fe57fbbac

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 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.installed?
          result = Libis::Tools::Command.run(Libis::Format::Config[:java_cmd], "-version")
          return false unless result[:status] == 0
          File.exist?(Libis::Format::Config[:pdf_tool])
        end

        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_cmd],
              '-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?

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

        end
      end

    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
libis-format-1.2.7 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.6 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.5 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.3 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.2 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.1 lib/libis/format/tool/pdf_split.rb
libis-format-1.2.0 lib/libis/format/tool/pdf_split.rb
libis-format-1.1.0 lib/libis/format/tool/pdf_split.rb