Sha256: a1283fc4a42e6a81d8e569a752ee65d087214b72eca3ac39e93f3a4fae628a53

Contents?: true

Size: 1.53 KB

Versions: 10

Compression:

Stored size: 1.53 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 PdfCopy
        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_copy]
          result = Libis::Tools::Command.run(
              Libis::Format::Config[:java_cmd],
              '-cp', Libis::Format::Config[:pdf_tool],
              'CopyPdf',
              '--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 ]
          }

        end
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

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