Class: Docsplit::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/docsplit/command_line.rb

Overview

A single command-line utility to separate a PDF into all its component parts.

Constant Summary collapse

<<-EOS
docsplit breaks apart documents into images, text, or individual pages.
It wraps GraphicsMagick, Poppler, PDFTK, and JODConverter.

Usage:
  docsplit COMMAND [OPTIONS] path/to/doc.pdf
  Main commands:
pages, images, text, pdf.
  Metadata commands:
author, date, creator, keywords, producer, subject, title, length.

Example:
  docsplit images --size 700x --format jpg document.pdf

Dependencies:
  Ruby, Java, A working GraphicsMagick (gm) command,
  and a headless OpenOffice server for non-PDF documents.

Options:
(size, pages and format can take comma-separated values)

EOS

Instance Method Summary collapse

Constructor Details

#initializeCommandLine

Creating a CommandLine runs off of the contents of ARGV.



33
34
35
36
37
38
# File 'lib/docsplit/command_line.rb', line 33

def initialize
  parse_options
  cmd = ARGV.shift
  @command = cmd && cmd.to_sym
  run
end

Instance Method Details

#runObject

Delegate to the Docsplit Ruby API to perform all extractions.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/docsplit/command_line.rb', line 41

def run
  begin
    case @command
    when :images  then Docsplit.extract_images(ARGV, @options)
    when :pages   then Docsplit.extract_pages(ARGV, @options)
    when :text    then Docsplit.extract_text(ARGV, @options)
    when :pdf     then Docsplit.extract_pdf(ARGV, @options)
    else
      if METADATA_KEYS.include?(@command)
        value = Docsplit.send("extract_#{@command}", ARGV, @options)
        puts value unless value.nil?
      else
        usage
      end
    end
  rescue ExtractionFailed => e
    puts e.message.chomp
    exit(1)
  end
end

#usageObject

Print out the usage help message.



63
64
65
66
# File 'lib/docsplit/command_line.rb', line 63

def usage
  puts "\n#{@option_parser}\n"
  exit
end