class PDF::Reader

:pages
:metadata
Available options are currently:
PDF::Reader.new(“somefile.pdf”, receiver, {:metadata => true, :pages => false})
but explicitly enables processing metadata.
As an example, the following call will disable parsing the contents of pages in the file,
to cut down processing time if you’re only interested in say, metadata.
parts of the file to process. By default, all options are enabled, so this can be useful
Both PDF::Reader#file and PDF::Reader#string accept a 3 argument that specifies which
= Parsing parts of a file
pdf.parse(File.new(“somefile.pdf”), receiver)
pdf = PDF::Reader.new
This can be a useful alternative to the first 2 options in some situations
= Parsing an IO object
PDF::Reader.string(pdf_string, receiver)
This is useful for processing a PDF that is already in memory
= Parsing a String
PDF::Reader.file(“somefile.pdf”, receiver)
= Parsing a file
on receivers.
to various callbacks. Refer to the README and PDF::Reader::Content for more information
For all examples, assume the receiver variable contains an object that will respond
and the situation.
ways to kick off processing - which one you pick will be based on personal preference
The Reader class serves as an entry point for parsing a PDF file. There are three
###############################################################################

def self.file (name, receiver, opts = {})

Parse the file with the given name, sending events to the given receiver.
###############################################################################
def self.file (name, receiver, opts = {})
  File.open(name,"rb") do |f|
    new.parse(f, receiver, opts)
  end
end

def self.string (str, receiver, opts = {})

Parse the given string, sending events to the given receiver.
###############################################################################
def self.string (str, receiver, opts = {})
  StringIO.open(str) do |s|
    new.parse(s, receiver, opts)
  end
end

def initialize

Initialize a new PDF::Reader
###############################################################################
def initialize
end

def parse (io, receiver, opts = {})

Given an IO object that contains PDF data, parse it.
###############################################################################
def parse (io, receiver, opts = {})
  @buffer   = Buffer.new(io)
  @xref     = XRef.new(@buffer)
  @parser   = Parser.new(@buffer, @xref)
  @content  = (receiver == Explore ? Explore : Content).new(receiver, @xref)
  options = {:pages => true, :metadata => true}
  options.merge!(opts)
  trailer = @xref.load
  @content.metadata(@xref.object(trailer[:Info]).first) if options[:metadata]
  @content.document(@xref.object(trailer[:Root]).first) if options[:pages]
  self
end