Sha256: 8dd82aedadbf7d1bf9f83341e2e5ee575d47f053cb1e8af6c484041e519b2de7

Contents?: true

Size: 1.11 KB

Versions: 12

Compression:

Stored size: 1.11 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 PdfOptimizer
        include ::Libis::Tools::Logger

        def self.run(source, target, quality)
          self.new.run source, target, quality
        end

        def run(source, target, quality)

          timeout = Libis::Format::Config[:timeouts][:pdf_optimizer]
          result = Libis::Tools::Command.run(
              'gs',
              '-sDEVICE=pdfwrite',
              '-dCompatibilityLevel=1.4',
              "-dPDFSETTINGS=/#{quality}",
              '-dNOPAUSE',
              '-dBATCH',
              "-sOutputFile=#{target}",
              "#{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
        end
      end

    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
libis-format-1.0.8 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.5 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.4 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.3 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.2 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.1 lib/libis/format/tool/pdf_optimizer.rb
libis-format-2.0.0 lib/libis/format/tool/pdf_optimizer.rb
libis-format-1.0.7 lib/libis/format/tool/pdf_optimizer.rb
libis-format-1.0.5 lib/libis/format/tool/pdf_optimizer.rb
libis-format-1.0.4 lib/libis/format/tool/pdf_optimizer.rb
libis-format-1.0.2 lib/libis/format/tool/pdf_optimizer.rb
libis-format-1.0.1 lib/libis/format/tool/pdf_optimizer.rb