Class: Origami::Trailer
- Inherits:
-
Object
- Object
- Origami::Trailer
- Includes:
- StandardObject
- Defined in:
- lib/origami/trailer.rb,
lib/origami/obfuscation.rb
Overview
Class representing a PDF file Trailer.
Constant Summary collapse
- TOKENS =
:nodoc:
%w{ trailer %%EOF }
- XREF_TOKEN =
:nodoc:
"startxref"
- @@regexp_open =
Regexp.new(WHITESPACES + TOKENS.first + WHITESPACES)
- @@regexp_xref =
Regexp.new(WHITESPACES + XREF_TOKEN + WHITESPACES + "(\\d+)")
- @@regexp_close =
Regexp.new(WHITESPACES + TOKENS.last + WHITESPACES)
Constants included from StandardObject
StandardObject::DEFAULT_ATTRIBUTES
Instance Attribute Summary collapse
-
#dictionary ⇒ Object
Returns the value of attribute dictionary.
-
#pdf ⇒ Object
Returns the value of attribute pdf.
-
#startxref ⇒ Object
Returns the value of attribute startxref.
Class Method Summary collapse
-
.parse(stream) ⇒ Object
:nodoc:.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #has_dictionary? ⇒ Boolean
-
#initialize(startxref = 0, dictionary = {}) ⇒ Trailer
constructor
Creates a new Trailer.
- #to_obfuscated_str ⇒ Object
-
#to_s ⇒ Object
Outputs self into PDF code.
Methods included from StandardObject
#do_type_check, #has_field?, included, #pdf_version_required, #pre_build, #set_default_value, #set_default_values
Constructor Details
#initialize(startxref = 0, dictionary = {}) ⇒ Trailer
Creates a new Trailer.
- startxref
-
The file offset to the XRef::Section.
- dictionary
-
A hash of attributes to set in the Trailer Dictionary.
113 114 115 116 |
# File 'lib/origami/trailer.rb', line 113 def initialize(startxref = 0, dictionary = {}) @startxref, self.dictionary = startxref, dictionary && Dictionary.new(dictionary) end |
Instance Attribute Details
#dictionary ⇒ Object
Returns the value of attribute dictionary.
98 99 100 |
# File 'lib/origami/trailer.rb', line 98 def dictionary @dictionary end |
#pdf ⇒ Object
Returns the value of attribute pdf.
96 97 98 |
# File 'lib/origami/trailer.rb', line 96 def pdf @pdf end |
#startxref ⇒ Object
Returns the value of attribute startxref.
97 98 99 |
# File 'lib/origami/trailer.rb', line 97 def startxref @startxref end |
Class Method Details
.parse(stream) ⇒ Object
:nodoc:
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/origami/trailer.rb', line 118 def self.parse(stream) #:nodoc: if stream.skip(@@regexp_open) dictionary = Dictionary.parse(stream) else dictionary = nil end if not stream.scan(@@regexp_xref) #raise InvalidTrailerError, "Cannot get startxref value" end startxref = (stream[3] && stream[3].to_i) if not stream.scan(@@regexp_close) #raise InvalidTrailerError, "No %%EOF token found" end Trailer.new(startxref, dictionary && dictionary.to_h) end |
Instance Method Details
#[](key) ⇒ Object
139 140 141 |
# File 'lib/origami/trailer.rb', line 139 def [](key) @dictionary[key] if has_dictionary? end |
#[]=(key, val) ⇒ Object
143 144 145 |
# File 'lib/origami/trailer.rb', line 143 def []=(key,val) @dictionary[key] = val end |
#has_dictionary? ⇒ Boolean
152 153 154 |
# File 'lib/origami/trailer.rb', line 152 def has_dictionary? not @dictionary.nil? end |
#to_obfuscated_str ⇒ Object
220 221 222 223 224 225 226 227 228 229 |
# File 'lib/origami/obfuscation.rb', line 220 def content = "" if self.has_dictionary? content << TOKENS.first << EOL << @dictionary. << EOL end content << XREF_TOKEN << EOL << @startxref.to_s << EOL << TOKENS.last << EOL content end |
#to_s ⇒ Object
Outputs self into PDF code.
159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/origami/trailer.rb', line 159 def to_s content = "" if self.has_dictionary? content << TOKENS.first << EOL << @dictionary.to_s << EOL end content << XREF_TOKEN << EOL << @startxref.to_s << EOL << TOKENS.last << EOL content end |