Class: HexaPDF::Type::XRefStream
- Inherits:
-
Stream
- Object
- Object
- Dictionary
- Stream
- HexaPDF::Type::XRefStream
- Defined in:
- lib/hexapdf/type/xref_stream.rb
Overview
Represents PDF type XRef, cross-reference streams.
A cross-reference stream is used as a more compact representation for an cross-reference section and trailer dictionary. The trailer dictionary is incorporated into the stream dictionary and the cross-reference section entries are stored in the stream itself, compressed to save space.
How are Cross-reference Streams Used?
Cross-reference stream objects are only used when parsing or writing a PDF document.
When a file is read and a cross-reference stream is found, it is loaded and its information is stored in a HexaPDF::Revision object. So from a user’s perspective nothing changes when a cross-reference stream instead of a cross-reference section and trailer is encountered.
This also means that all information stored in a cross-reference stream between parsing and writing is discarded when the PDF document gets written!
Upon writing a revision it is checked whether that revision contains a cross-reference stream object. If it does the cross-reference stream object is updated with the cross-reference section and trailer information and then written. Otherwise a normal cross-reference section plus trailer are written.
See: PDF1.7 s7.5.8
Constant Summary
Constants included from DictionaryFields
DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate
Constants inherited from Object
Object::NOT_DUPLICATABLE_CLASSES
Instance Attribute Summary
Attributes inherited from Object
#data, #document, #must_be_indirect
Instance Method Summary collapse
-
#trailer ⇒ Object
Returns a hash with the entries that represent the file trailer part of the cross-reference stream’s dictionary.
-
#update_with_xref_section_and_trailer(xref_section, trailer) ⇒ Object
Makes this cross-reference stream represent the data in the given HexaPDF::XRefSection and Type::Trailer.
-
#xref_section ⇒ Object
Returns an XRefSection that represents the content of this cross-reference stream.
Methods inherited from Stream
#must_be_indirect?, #raw_stream, #set_filter, #stream, #stream=, #stream_decoder, #stream_encoder, #stream_source
Methods inherited from Dictionary
#[], #[]=, define_field, #delete, #each, each_field, #empty?, field, #key?, #to_hash, #type
Methods inherited from Object
#<=>, #==, deep_copy, #deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #must_be_indirect?, #null?, #oid, #oid=, #type, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#trailer ⇒ Object
Returns a hash with the entries that represent the file trailer part of the cross-reference stream’s dictionary.
See: Type::Trailer
90 91 92 93 94 |
# File 'lib/hexapdf/type/xref_stream.rb', line 90 def trailer Trailer.each_field.with_object({}) do |(name, _data), hash| hash[name] = value[name] if key?(name) end end |
#update_with_xref_section_and_trailer(xref_section, trailer) ⇒ Object
Makes this cross-reference stream represent the data in the given HexaPDF::XRefSection and Type::Trailer.
The given cross-reference section is not stored but only used to rewrite the associated stream to reflect the cross-reference section. The dictionary is updated with the information from the trailer and the needed entries for the cross-reference section.
If there are changes to the cross-reference section or trailer, this method has to be invoked again.
105 106 107 108 109 110 |
# File 'lib/hexapdf/type/xref_stream.rb', line 105 def update_with_xref_section_and_trailer(xref_section, trailer) value.replace(trailer) value[:Type] = :XRef write_xref_section_to_stream(xref_section) set_filter(:FlateDecode, Columns: value[:W].inject(:+), Predictor: 12) end |
#xref_section ⇒ Object
Returns an XRefSection that represents the content of this cross-reference stream.
Each invocation returns a new XRefSection object based on the current data in the associated stream and dictionary.
81 82 83 84 |
# File 'lib/hexapdf/type/xref_stream.rb', line 81 def xref_section index = self[:Index] || [0, self[:Size]] parse_xref_section(index, self[:W]) end |