class HexaPDF::XRefSection
Manages the indirect objects of one cross-reference section or stream.
A PDF file can have more than one cross-reference section or stream which are all daisy-chained together. This allows later sections to override entries in prior ones. This is automatically and transparently done by HexaPDF
.
Note that a cross-reference section may contain a single object number only once.
See: HexaPDF::Revision
, PDF1.7 s7.5.4, s7.5.8
Constants
- Entry
One entry of a cross-reference section or stream.
An entry has the attributes
type
,oid
,gen
,pos
andobjstm
and can be created like this:Entry.new(type, oid, gen, pos, objstm) -> entry
The
type
attribute can be:- :free
-
Denotes a free entry.
- :in_use
-
A used entry that resides in the body of the PDF file. The
pos
attribute defines the position in the file at which the object can be found. - :compressed
-
A used entry that resides in an object stream. The
objstm
attribute contains the reference to the object stream in which the object can be found and thepos
attribute contains the index into the object stream.Objects in an object stream always have a generation number of 0!
See: PDF1.7 s7.5.4, s7.5.8
Public Class Methods
Creates a compressed cross-reference entry. See Entry
for details on the arguments.
# File lib/hexapdf/xref_section.rb, line 105 def self.compressed_entry(oid, objstm, pos) Entry.new(:compressed, oid, 0, pos, objstm) end
Creates a free cross-reference entry. See Entry
for details on the arguments.
# File lib/hexapdf/xref_section.rb, line 100 def self.free_entry(oid, gen) Entry.new(:free, oid, gen) end
Creates an in-use cross-reference entry. See Entry
for details on the arguments.
# File lib/hexapdf/xref_section.rb, line 95 def self.in_use_entry(oid, gen, pos) Entry.new(:in_use, oid, gen, pos) end
Public Instance Methods
Adds a compressed entry to the cross-reference section.
See: ::compressed_entry
# File lib/hexapdf/xref_section.rb, line 130 def add_compressed_entry(oid, objstm, pos) self[oid, 0] = self.class.compressed_entry(oid, objstm, pos) end
Adds a free entry to the cross-reference section.
See: ::free_entry
# File lib/hexapdf/xref_section.rb, line 123 def add_free_entry(oid, gen) self[oid, gen] = self.class.free_entry(oid, gen) end
Adds an in-use entry to the cross-reference section.
See: ::in_use_entry
# File lib/hexapdf/xref_section.rb, line 116 def add_in_use_entry(oid, gen, pos) self[oid, gen] = self.class.in_use_entry(oid, gen, pos) end
Calls the given block once for every subsection of this cross-reference section. Each yielded subsection is a sorted array of cross-reference entries.
If this section contains no objects, a single empty array is yielded (corresponding to a subsection with zero elements).
The subsections are dynamically generated based on the object numbers in this section.
# File lib/hexapdf/xref_section.rb, line 150 def each_subsection return to_enum(__method__) unless block_given? temp = [] oids.sort.each do |oid| if !temp.empty? && temp[-1].oid + 1 != oid yield(temp) temp = [] end temp << self[oid] end yield(temp) self end
Merges the entries from the given cross-reference section into this one.
# File lib/hexapdf/xref_section.rb, line 135 def merge!(xref_section) xref_section.each {|oid, gen, data| self[oid, gen] = data } end