Class: Origami::PDF::LinearParser

Inherits:
Parser show all
Defined in:
lib/origami/parsers/pdf/linear.rb

Overview

Create a new PDF linear Parser.

Constant Summary

Constants inherited from Origami::Parser

Origami::Parser::VERBOSE_DEBUG, Origami::Parser::VERBOSE_INFO, Origami::Parser::VERBOSE_INSANE, Origami::Parser::VERBOSE_QUIET

Instance Attribute Summary

Attributes inherited from Origami::Parser

#options

Instance Method Summary collapse

Methods inherited from Parser

#initialize

Methods inherited from Origami::Parser

#defer_type_cast, #initialize, #parse_object, #parse_trailer, #parse_xreftable, #target_data, #target_filename, #target_filesize

Constructor Details

This class inherits a constructor from Origami::PDF::Parser

Instance Method Details

#parse(stream) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/origami/parsers/pdf/linear.rb', line 34

def parse(stream)
  super
  
  pdf = parse_initialize

  #
  # Parse each revision
  #
  revision = 0
  until @data.eos? do
    
    begin
      pdf.add_new_revision unless revision.zero?
      revision = revision + 1

      info "...Parsing revision #{pdf.revisions.size}..."
      loop do
        break if (object = parse_object).nil?
        pdf.insert(object)
      end

      pdf.revisions.last.xreftable = parse_xreftable

      trailer = parse_trailer
      pdf.revisions.last.trailer = trailer

      xrefstm = pdf.get_object_by_offset(trailer.startxref) || 
        (pdf.get_object_by_offset(trailer.XRefStm) if trailer.has_field? :XRefStm)

      if not xrefstm.nil?
        warn "Found a XRefStream for this revision at #{xrefstm.reference}"
        pdf.revisions.last.xrefstm = xrefstm
      end

    rescue SystemExit
      raise
    rescue Exception => e
      error "Cannot read : " + (@data.peek(10) + "...").inspect
      error "Stopped on exception : " + e.message

      break
    end

  end

  parse_finalize(pdf)
end