Class: HexaPDF::Type::Trailer
- Inherits:
-
Dictionary
- Object
- Object
- Dictionary
- HexaPDF::Type::Trailer
- Defined in:
- lib/hexapdf/type/trailer.rb
Overview
Represents the PDF file trailer.
The file trailer is the starting point for the PDF’s object tree. It links to the Catalog (the main PDF document structure) and the Info dictionary and holds the information necessary for encrypting the PDF document.
Since a PDF document can contain multiple revisions, each revision needs to have its own file trailer (see HexaPDF::Revision#trailer).
When cross-reference streams are used the information that is normally stored in the file trailer is stored directly in the cross-reference stream dictionary. However, a HexaPDF::Revision object’s trailer dictionary is always of this type. Only when a cross-reference stream is written is the trailer integrated into the stream’s dictionary.
See: PDF1.7 s7.5.5, s14.4
XRefStream
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
-
#catalog ⇒ Object
Returns the document’s Catalog (see Type::Catalog), creating it if needed.
-
#info ⇒ Object
Returns the document’s information dictionary (see Type::Info), creating it if needed.
-
#set_random_id ⇒ Object
Sets the /ID field to an array of two copies of a random string and returns this array.
-
#type ⇒ Object
Returns
:XXTrailer
. -
#update_id ⇒ Object
Updates the second part of the /ID field (the first part should always be the same for a PDF file, the second part should change with each write).
Methods inherited from Dictionary
#[], #[]=, define_field, #delete, #each, each_field, #empty?, field, #key?, #to_hash
Methods inherited from Object
#<=>, #==, deep_copy, #deep_copy, #document?, #eql?, #gen, #gen=, #hash, #indirect?, #initialize, #inspect, #must_be_indirect?, #null?, #oid, #oid=, #validate, #value, #value=
Constructor Details
This class inherits a constructor from HexaPDF::Object
Instance Method Details
#catalog ⇒ Object
Returns the document’s Catalog (see Type::Catalog), creating it if needed.
72 73 74 |
# File 'lib/hexapdf/type/trailer.rb', line 72 def catalog self[:Root] ||= document.add(Type: :Catalog) end |
#info ⇒ Object
Returns the document’s information dictionary (see Type::Info), creating it if needed.
77 78 79 |
# File 'lib/hexapdf/type/trailer.rb', line 77 def info self[:Info] ||= document.add({}, type: :XXInfo) end |
#set_random_id ⇒ Object
Sets the /ID field to an array of two copies of a random string and returns this array.
See: PDF1.7 14.4
84 85 86 |
# File 'lib/hexapdf/type/trailer.rb', line 84 def set_random_id value[:ID] = [Digest::MD5.digest(rand.to_s)] * 2 end |
#type ⇒ Object
Returns :XXTrailer
.
67 68 69 |
# File 'lib/hexapdf/type/trailer.rb', line 67 def type :XXTrailer end |
#update_id ⇒ Object
Updates the second part of the /ID field (the first part should always be the same for a PDF file, the second part should change with each write).
90 91 92 93 94 95 96 |
# File 'lib/hexapdf/type/trailer.rb', line 90 def update_id if !value[:ID].kind_of?(Array) set_random_id else value[:ID][1] = Digest::MD5.digest(rand.to_s) end end |