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: PDF2.0 s7.5.8
Constant Summary
Constants included from DictionaryFields
DictionaryFields::Boolean, DictionaryFields::PDFByteString, DictionaryFields::PDFDate
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, define_type, #delete, #each, each_field, #empty?, field, #key?, #to_hash, type, #type
Methods inherited from Object
#<=>, #==, #cache, #cached?, #clear_cache, deep_copy, #deep_copy, #document?, #eql?, field, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, make_direct, #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
93 94 95 96 97 98 |
# File 'lib/hexapdf/type/xref_stream.rb', line 93 def trailer trailer = {Type: :XRef} Trailer.each_field.with_object(trailer) 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 xref_section
needs to contain an entry for this cross-reference stream and it is necessary that this entry is the one with the highest byte position (for calculating the correct /W entry).
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.
113 114 115 116 117 118 |
# File 'lib/hexapdf/type/xref_stream.rb', line 113 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.
84 85 86 87 |
# File 'lib/hexapdf/type/xref_stream.rb', line 84 def xref_section index = self[:Index] || [0, self[:Size]] parse_xref_section(index, self[:W]) end |