lib/hexapdf/parser.rb in hexapdf-0.8.0 vs lib/hexapdf/parser.rb in hexapdf-0.9.0

- old
+ new

@@ -43,10 +43,13 @@ # This class also contains higher-level methods for getting indirect objects and revisions. # # See: PDF1.7 s7 class Parser + # The IO stream which is parsed. + attr_reader :io + # Creates a new parser for the given IO object. # # PDF references are resolved using the associated Document object. def initialize(io, document) @io = io @@ -268,10 +271,12 @@ # # If strict parsing is disabled, the whole file is searched for the offset. # # See: PDF1.7 s7.5.5, ADB1.7 sH.3-3.4.4 def startxref_offset + return @startxref_offset if defined?(@startxref_offset) + @io.seek(0, IO::SEEK_END) step_size = 1024 pos = @io.pos eof_not_found = startxref_missing = false @@ -299,10 +304,10 @@ elsif startxref_missing maybe_raise("PDF file trailer is missing startxref keyword", pos: pos, force: eof_index < 2 || lines[eof_index - 2].strip != "startxref") end - lines[eof_index - 1].to_i + @startxref_offset = lines[eof_index - 1].to_i end # Returns the PDF version number that is stored in the file header. # # See: PDF1.7 s7.5.2