class PDF::Reader::XRef

def load_xref_table(buf)

Xref table and processes it into memory.
Assumes the underlying buffer is positioned at the start of a traditional
###############################################################################
def load_xref_table(buf)
  params = []
  while !params.include?("trailer") && !params.include?(nil)
    if params.size == 2
      objid, count = params[0].to_i, params[1].to_i
      count.times do
        offset = buf.token.to_i
        generation = buf.token.to_i
        state = buf.token
        # Some PDF writers start numbering at 1 instead of 0. Fix up the number.
        # TODO should this fix be logged?
        objid = 0 if objid == 1 and offset == 0 and generation == 65535 and state == 'f'
        store(objid, generation, offset + @junk_offset) if state == "n" && offset > 0
        objid += 1
        params.clear
      end
    end
    params << buf.token
  end
  trailer = Parser.new(buf, self).parse_token
  unless trailer.kind_of?(Hash)
    raise MalformedPDFError, "PDF malformed, trailer should be a dictionary"
  end
  load_offsets(trailer[:XRefStm])   if trailer.has_key?(:XRefStm)
  # Some PDF creators seem to use '/Prev 0' in trailer if there is no previous xref
  # It's not possible for an xref to appear at offset 0, so can safely skip the ref
  load_offsets(trailer[:Prev].to_i) if trailer.has_key?(:Prev) and trailer[:Prev].to_i != 0
  trailer
end