def load_xref_table
tok_one = tok_two = nil
begin
loop do
tok_one, tok_two = @buffer.token, @buffer.token
if tok_one != "trailer" && !tok_one.match(/\d+/)
raise MalformedPDFError, "PDF malformed, missing trailer after cross reference"
end
break if tok_one == "trailer" or tok_one.nil?
objid, count = tok_one.to_i, tok_two.to_i
count.times do
offset = @buffer.token.to_i
generation = @buffer.token.to_i
state = @buffer.token
store(objid, generation, offset) if state == "n"
objid += 1
end
end
rescue EOFError => e
raise MalformedPDFError, "PDF malformed, missing trailer after cross reference"
end
raise MalformedPDFError, "PDF malformed, trailer should be a dictionary" unless tok_two == "<<"
trailer = Parser.new(@buffer, self).dictionary
load(trailer[:Prev].to_i) if trailer.has_key?(:Prev)
trailer
end