Sha256: a97ad41c183470ce606a57e4764d9a622196254a0f92ed2d41473e7cc0340817

Contents?: true

Size: 1.39 KB

Versions: 4

Compression:

Stored size: 1.39 KB

Contents

# encoding: utf-8

require_relative 'base'

require 'libis/format/tool/pdf_split'

module Libis
  module Format
    module Converter

      # noinspection DuplicatedCode
      class PdfSplitter < Libis::Format::Converter::Base

        def self.input_types
          [:PDF]
        end

        def self.output_types(format = nil)
          return [] unless input_types.include?(format) if format
          [:PDFA]
        end

        def self.category
          :splitter
        end

        def initialize
          super
        end

        # Split at given page. If omitted, nil or 0, the source PDF will be split at every page
        def page(v)
          @options[:page] = v unless v.blank?
        end

        def convert(source, target, format, opts = {})
          super

          result = split(source, target)
          return nil unless result

          result
        end

        private

        def split(source, target)

          result = Libis::Format::Tool::PdfSplit.run(
            source, target,
            @options.map { |k, v|
              if v.nil?
                nil
              else
                ["--#{k}", v]
              end }.compact.flatten
          )
          unless result[:err].empty?
            error("Pdf split encountered errors:\n%s", result[:err].join(join("\n")))
            return nil
          end
          result[:out]

        end

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
libis-format-2.0.4 lib/libis/format/converter/pdf_splitter.rb
libis-format-2.0.3 lib/libis/format/converter/pdf_splitter.rb
libis-format-2.0.2 lib/libis/format/converter/pdf_splitter.rb
libis-format-2.0.1 lib/libis/format/converter/pdf_splitter.rb