Class: PDF::Reader
- Inherits:
-
Object
- Object
- PDF::Reader
- Defined in:
- lib/pdf/reader.rb,
lib/pdf/reader/lzw.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/encoding.rb,
lib/pdf/reader/reference.rb,
lib/pdf/reader/object_hash.rb,
lib/pdf/reader/object_stream.rb,
lib/pdf/reader/text_receiver.rb,
lib/pdf/reader/pages_strategy.rb,
lib/pdf/reader/print_receiver.rb,
lib/pdf/reader/abstract_strategy.rb,
lib/pdf/reader/metadata_strategy.rb,
lib/pdf/reader/register_receiver.rb
Overview
Copyright © 2010 James Healy ([email protected])
Defined Under Namespace
Classes: AbstractStrategy, Buffer, CMap, Encoding, Error, Filter, Font, InvalidObjectError, LZW, MalformedPDFError, MetadataStrategy, ObjectHash, ObjectStream, PagesStrategy, 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 = 0) ⇒ Object
Parse the file with the given name, returning an unmarshalled ruby version of represents the requested pdf object.
-
.object_string(str, id, gen = 0) ⇒ Object
Parse the given string, returning an unmarshalled ruby version of represents the requested pdf 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.
80 81 82 83 84 |
# File 'lib/pdf/reader.rb', line 80 def self.file(name, receiver, opts = {}) File.open(name,"rb") do |f| new.parse(f, receiver, opts) end end |
.object_file(name, id, gen = 0) ⇒ Object
Parse the file with the given name, returning an unmarshalled ruby version of represents the requested pdf object
97 98 99 100 101 |
# File 'lib/pdf/reader.rb', line 97 def self.object_file(name, id, gen = 0) File.open(name,"rb") { |f| new.object(f, id.to_i, gen.to_i) } end |
.object_string(str, id, gen = 0) ⇒ Object
Parse the given string, returning an unmarshalled ruby version of represents the requested pdf object
106 107 108 109 110 |
# File 'lib/pdf/reader.rb', line 106 def self.object_string(str, id, gen = 0) StringIO.open(str) { |s| new.object(s, id.to_i, gen.to_i) } end |
.string(str, receiver, opts = {}) ⇒ Object
Parse the given string, sending events to the given receiver.
88 89 90 91 92 |
# File 'lib/pdf/reader.rb', line 88 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
133 134 135 136 137 |
# File 'lib/pdf/reader.rb', line 133 def object (io, id, gen) @ohash = ObjectHash.new(io) @ohash.object(Reference.new(id, gen)) end |
#parse(io, receiver, opts = {}) ⇒ Object
Given an IO object that contains PDF data, parse it.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pdf/reader.rb', line 114 def parse(io, receiver, opts = {}) ohash = ObjectHash.new(io) if ohash.trailer[:Encrypt] raise ::PDF::Reader::UnsupportedFeatureError, 'PDF::Reader cannot read encrypted PDF files' end = {:pages => true, :raw_text => false, :metadata => true} .merge!(opts) strategies.each do |s| s.new(ohash, receiver, ).process end self end |