Class: PDF::Reader::XRef

### Home Classes Methods

### In Files

- lib/pdf/reader/xref.rb

### Parent

Object

### Methods

- ::new
- #[]
- #each
- #size

### Included Modules

- Enumerable

### Files

- MIT-LICENSE
- README.rdoc
- TODO
- mac_expert.txt
- mac_roman.txt
- pdf_doc.txt
- standard.txt
- symbol.txt
- win_ansi.txt
- zapf_dingbats.txt
- glyphlist.txt

### Class/Module Index

Quicksearch

- PDF
- PDF::Reader
- PDF::Reader::Buffer
- PDF::Reader::CidWidths
- PDF::Reader::EncryptedPDFError
- PDF::Reader::Filter
- PDF::Reader::Filter::Ascii85
- PDF::Reader::Filter::AsciiHex
- PDF::Reader::Filter::Depredict
- PDF::Reader::Filter::Flate
- PDF::Reader::Filter::Lzw
- PDF::Reader::Filter::Null
- PDF::Reader::Filter::RunLength
- PDF::Reader::Font
- PDF::Reader::FontDescriptor
- PDF::Reader::FormXObject
- PDF::Reader::InvalidObjectError
- PDF::Reader::MalformedPDFError
- PDF::Reader::ObjectCache
- PDF::Reader::ObjectHash
- PDF::Reader::PageLayout
- PDF::Reader::PageState
- PDF::Reader::PageTextReceiver
- PDF::Reader::Parser
- PDF::Reader::PrintReceiver
- PDF::Reader::Reference
- PDF::Reader::RegisterReceiver
- PDF::Reader::ResourceMethods
- PDF::Reader::StandardSecurityHandler
- PDF::Reader::Stream
- PDF::Reader::SynchronizedCache
- PDF::Reader::TextReceiver
- PDF::Reader::TextRun
- PDF::Reader::TransformationMatrix
- PDF::Reader::UnsupportedFeatureError
- PDF::Reader::WidthCalculator
- PDF::Reader::WidthCalculator::BuiltIn
- PDF::Reader::WidthCalculator::Composite
- PDF::Reader::WidthCalculator::TrueType
- PDF::Reader::WidthCalculator::TypeOneOrThree
- PDF::Reader::WidthCalculator::TypeZero
- PDF::Reader::XRef
- AFM
- AFM::Font

No matching classes.

# PDF::Reader::XRef

An internal PDF::Reader class that represents the XRef table in a PDF file as a hash-like object.

An Xref table is a map of object identifiers and byte offsets. Any time a particular object needs to be found, the Xref table is used to find where it is stored in the file.

Hash keys are object ids, values are either:

- a byte offset where the object starts (regular PDF objects)

- a PDF::Reader::Reference instance that points to a stream that contains the desired object (PDF objects embedded in an object stream)

The class behaves much like a standard Ruby hash, including the use of the Enumerable mixin. The key difference is no []= method - the hash is read only.

### Attributes

trailer[R]

### Public Class Methods

new(io) click to toggle source

create a new Xref table based on the contents of the supplied io object

io - must be an IO object, generally either a file or a StringIO

    # File lib/pdf/reader/xref.rb, line 55
    def initialize (io)
      @io = io
      @junk_offset = calc_junk_offset(io) || 0
      @xref = {}
      @trailer = load_offsets
    end

### Public Instance Methods

[](ref) click to toggle source

returns the byte offset for the specified PDF object.

ref - a PDF::Reader::Reference object containing an object ID and revision number

    # File lib/pdf/reader/xref.rb, line 72
    def [](ref)
      @xref[ref.id][ref.gen]
    rescue
      raise InvalidObjectError, "Object #{ref.id}, Generation #{ref.gen} is invalid"
    end

each(&block) click to toggle source

iterate over each object in the xref table

    # File lib/pdf/reader/xref.rb, line 79
    def each(&block)
      ids = @xref.keys.sort
      ids.each do |id|
        gen = @xref[id].keys.sort[-1]
        yield PDF::Reader::Reference.new(id, gen)
      end
    end

size() click to toggle source

return the number of objects in this file. Objects with multiple generations are only counter once.

    # File lib/pdf/reader/xref.rb, line 65
    def size
      @xref.size
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.