Class: PDF::Reader
- Inherits:
-
Object
- Object
- PDF::Reader
- Defined in:
- lib/pdf/reader.rb,
lib/pdf/reader.rb,
lib/pdf/reader/cmap.rb,
lib/pdf/reader/font.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/stream.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/print_receiver.rb,
lib/pdf/reader/register_receiver.rb
Overview
Copyright © 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, InvalidObjectError, MalformedPDFError, Parser, PrintReceiver, Reference, RegisterReceiver, Stream, TextReceiver, Token, UnsupportedFeatureError, XRef
Class Method Summary collapse
-
.file(name, receiver, opts = {}) ⇒ Object
Parse the file with the given name, sending events to the given receiver.
- .object_file(name, id, gen) ⇒ Object
- .object_string(name, id, gen) ⇒ Object
-
.string(str, receiver, opts = {}) ⇒ Object
Parse the given string, sending events to the given receiver.
Instance Method Summary collapse
-
#object(io, id, gen) ⇒ Object
Given an IO object that contains PDF data, return the contents of a single object.
-
#parse(io, receiver, opts = {}) ⇒ Object
Given an IO object that contains PDF data, parse it.
Class Method Details
.file(name, receiver, opts = {}) ⇒ Object
Parse the file with the given name, sending events to the given receiver.
74 75 76 77 78 |
# File 'lib/pdf/reader.rb', line 74 def self.file(name, receiver, opts = {}) File.open(name,"rb") do |f| new.parse(f, receiver, opts) end end |
.object_file(name, id, gen) ⇒ Object
87 88 89 90 91 |
# File 'lib/pdf/reader.rb', line 87 def self.object_file(name, id, gen) File.open(name,"rb") do |f| new.object(f, id, gen) end end |
.object_string(name, id, gen) ⇒ Object
93 94 95 96 97 |
# File 'lib/pdf/reader.rb', line 93 def self.object_string(name, id, gen) StringIO.open(str) do |s| new.object(s, id, gen) end end |
.string(str, receiver, opts = {}) ⇒ Object
Parse the given string, sending events to the given receiver.
81 82 83 84 85 |
# File 'lib/pdf/reader.rb', line 81 def self.string(str, receiver, opts = {}) StringIO.open(str) do |s| new.parse(s, receiver, opts) end end |
Instance Method Details
#object(io, id, gen) ⇒ Object
Given an IO object that contains PDF data, return the contents of a single object
141 142 143 144 145 146 147 |
# File 'lib/pdf/reader.rb', line 141 def object (io, id, gen) @buffer = Buffer.new(io) @xref = XRef.new(@buffer) @xref.load @xref.object(Reference.new(id, gen)) end |
#parse(io, receiver, opts = {}) ⇒ Object
Given an IO object that contains PDF data, parse it.
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/pdf/reader.rb', line 124 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) = {:pages => true, :metadata => true} .merge!(opts) trailer = @xref.load raise PDF::Reader::UnsupportedFeatureError, 'PDF::Reader cannot read encrypted PDF files' if trailer[:Encrypt] @content.(@xref.object(trailer[:Root]), @xref.object(trailer[:Info])) if [:metadata] @content.document(@xref.object(trailer[:Root])) if [:pages] self end |