Class: PDF::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/pdf/reader.rb,
lib/pdf/reader.rb,
lib/pdf/reader/cmap.rb,
lib/pdf/reader/font.rb,
lib/pdf/reader/name.rb,
lib/pdf/reader/xref.rb,
lib/pdf/reader/error.rb,
lib/pdf/reader/token.rb,
lib/pdf/reader/buffer.rb,
lib/pdf/reader/filter.rb,
lib/pdf/reader/parser.rb,
lib/pdf/reader/content.rb,
lib/pdf/reader/explore.rb,
lib/pdf/reader/encoding.rb,
lib/pdf/reader/reference.rb,
lib/pdf/reader/text_receiver.rb,
lib/pdf/reader/register_receiver.rb

Overview

Copyright (C) 2006 Peter J Jones ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Defined Under Namespace

Classes: Buffer, CMap, Content, Encoding, Error, Explore, Filter, Font, MalformedPDFError, Name, Parser, Reference, RegisterReceiver, TextReceiver, Token, UnsupportedFeatureError, XRef

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReader

Initialize a new PDF::Reader


94
95
# File 'lib/pdf/reader.rb', line 94

def initialize
end

Class Method Details

.file(name, receiver) ⇒ Object

Parse the file with the given name, sending events to the given receiver.


57
58
59
60
61
# File 'lib/pdf/reader.rb', line 57

def self.file (name, receiver)
  File.open(name,"rb") do |f|
    new.parse(f, receiver)
  end
end

.string(str, receiver) ⇒ Object

Parse the given string, sending events to the given receiver.


64
65
66
67
68
# File 'lib/pdf/reader.rb', line 64

def self.string (str, receiver)
  StringIO.open(str) do |s|
    new.parse(s, receiver)
  end
end

Instance Method Details

#parse(io, receiver) ⇒ Object

Given an IO object that contains PDF data, parse it.


98
99
100
101
102
103
104
105
106
# File 'lib/pdf/reader.rb', line 98

def parse (io, receiver)
  @buffer   = Buffer.new(io)
  @xref     = XRef.new(@buffer)
  @parser   = Parser.new(@buffer, @xref)
  @content  = (receiver == Explore ? Explore : Content).new(receiver, @xref)

  trailer = @xref.load
  @content.document(@xref.object(trailer['Root'])) || self
end