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_QUIET, Origami::Parser::VERBOSE_TRACE

Instance Attribute Summary

Attributes inherited from Origami::Parser

#options

Instance Method Summary collapse

Methods inherited from Parser

#initialize

Methods inherited from Origami::Parser

#debug, #defer_type_cast, #error, #info, #initialize, #parse_object, #parse_trailer, #parse_xreftable, #pos, #pos=, #target_data, #target_filename, #target_filesize, #trace, #warn

Constructor Details

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

Instance Method Details

#parse(stream) ⇒ Object


32
33
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
# File 'lib/origami/parsers/pdf/linear.rb', line 32

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

            locate_xref_stream(pdf, pdf.revisions.last)

        rescue
            error "Cannot read : " + (@data.peek(10) + "...").inspect
            error "Stopped on exception : " + $!.message

            break
        end
    end

    pdf.loaded!

    parse_finalize(pdf)
end