Sha256: bc3254f6fb88cbf259d608a8184b3ecb11254512903f6cc24b972403e6a32434

Contents?: true

Size: 990 Bytes

Versions: 26

Compression:

Stored size: 990 Bytes

Contents

# coding: utf-8

class PDF::Reader

  # provides a wrapper around a PDF stream object that contains other objects in it.
  # This is done for added compression and is described as an "Object Stream" in the spec.
  #
  class ObjectStream # :nodoc:
    def initialize(stream)
      @dict = stream.hash
      @data = stream.unfiltered_data
    end

    def [](objid)
      if offsets[objid].nil?
        nil
      else
        buf = PDF::Reader::Buffer.new(StringIO.new(@data), :seek => offsets[objid])
        parser = PDF::Reader::Parser.new(buf)
        parser.parse_token
      end
    end

    def size
      @dict[:N]
    end

    private

    def offsets
      @offsets ||= {}
      return @offsets if @offsets.keys.size > 0

      size.times do
        @offsets[buffer.token.to_i] = first + buffer.token.to_i
      end
      @offsets
    end

    def first
      @dict[:First]
    end

    def buffer
      @buffer ||= PDF::Reader::Buffer.new(StringIO.new(@data))
    end

  end

end

Version data entries

26 entries across 26 versions & 3 rubygems

Version Path
pdf-reader-2.1.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.0.0 lib/pdf/reader/object_stream.rb
pdf-reader-2.0.0.beta1 lib/pdf/reader/object_stream.rb
pdf-reader-1.4.1 lib/pdf/reader/object_stream.rb
pdf-reader-1.4.0 lib/pdf/reader/object_stream.rb
panjiva-pdf-reader-1.3.0 lib/pdf/reader/object_stream.rb
pdf-reader-1.3.3 lib/pdf/reader/object_stream.rb
pdf-reader-1.3.2 lib/pdf/reader/object_stream.rb
pdf-reader-1.3.1 lib/pdf/reader/object_stream.rb
pdf-reader-1.3.0 lib/pdf/reader/object_stream.rb
pdf-reader-1.2.0 lib/pdf/reader/object_stream.rb
pdf-reader-1.1.1 lib/pdf/reader/object_stream.rb
pdf-reader-1.1.0 lib/pdf/reader/object_stream.rb
pdf-reader-1.0.0 lib/pdf/reader/object_stream.rb
pdf-reader-1.0.0.rc1 lib/pdf/reader/object_stream.rb
pdf-reader-0.10.1 lib/pdf/reader/object_stream.rb
pdf-reader-1.0.0.beta1 lib/pdf/reader/object_stream.rb
pdf-reader-0.12.0.alpha lib/pdf/reader/object_stream.rb
fireinc-pdf-reader-0.11.0 lib/pdf/reader/object_stream.rb
fireinc-pdf-reader-0.11.0.alpha lib/pdf/reader/object_stream.rb