class Libis::Format::Converter::PdfSelecter

noinspection DuplicatedCode

Public Class Methods

input_types() click to toggle source
# File lib/libis/format/converter/pdf_selecter.rb, line 14
def self.input_types
  [:PDF]
end
new() click to toggle source
Calls superclass method Libis::Format::Converter::Base::new
# File lib/libis/format/converter/pdf_selecter.rb, line 27
def initialize
  super
  @options[:ranges] = []
end
output_types(format = nil) click to toggle source
# File lib/libis/format/converter/pdf_selecter.rb, line 18
def self.output_types(format = nil)
  return [] unless input_types.include?(format) if format
  [:PDF]
end

Public Instance Methods

convert(source, target, format, opts = {}) click to toggle source
Calls superclass method Libis::Format::Converter::Base#convert
# File lib/libis/format/converter/pdf_selecter.rb, line 51
def convert(source, target, format, opts = {})
  super

  result = nil

  unless @options.empty?
    result = convert_pdf(source, target)
    return nil unless result
  end

  result

end
convert_pdf(source, target) click to toggle source
# File lib/libis/format/converter/pdf_selecter.rb, line 65
def convert_pdf(source, target)

  using_temp(target) do |tmpname|
    opts = @options[:ranges].map { |range| ["-r", range] }.compact.flatten
    result = Libis::Format::Tool::PdfSelect.run(source, tmpname, opts)
    unless result[:err].empty?
      error("Pdf selection encountered errors:\n%s", result[:err].join(join("\n")))
      next nil
    end
    tmpname
  end

end
pdf_select(_) click to toggle source
# File lib/libis/format/converter/pdf_selecter.rb, line 23
def pdf_select(_)
  #force usage of this converter
end
range(selection) click to toggle source

Select a partial list of pages @param [String] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][e]start-end

# File lib/libis/format/converter/pdf_selecter.rb, line 34
def range(selection)
  @options[:ranges] += selection.split(/\s*,\s*/) unless selection.blank?
end
ranges(selection) click to toggle source

Select a partial list of pages @param [String|Array<String>] selection as described in com.itextpdf.text.pdf.SequenceList: [!][o][e]start-end

# File lib/libis/format/converter/pdf_selecter.rb, line 40
def ranges(selection)
  case selection
  when Array
    @options[:ranges] += selection.to_s unless selection.empty?
  when String
    range([selection])
  else
    # nothing
  end
end