Method: PDF::Reader::Buffer#find_first_xref_offset

Defined in:
lib/pdf/reader/buffer.rb

#find_first_xref_offsetObject

return the byte offset where the first XRef table in th source can be found.

Raises:



128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/pdf/reader/buffer.rb', line 128

def find_first_xref_offset
  check_size_is_non_zero
  @io.seek(-1024, IO::SEEK_END) rescue @io.seek(0)
  data = @io.read(1024)

  # the PDF 1.7 spec (section #3.4) says that EOL markers can be either \r, \n, or both.
  lines = data.split(/[\n\r]+/).reverse
  eof_index = lines.index { |l| l.strip[/^%%EOF/] }

  raise MalformedPDFError, "PDF does not contain EOF marker" if eof_index.nil?
  raise MalformedPDFError, "PDF EOF marker does not follow offset" if eof_index >= lines.size-1
  lines[eof_index+1].to_i
end