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
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.
121 122 123 124 |
# File 'lib/origami/trailer.rb', line 121 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.
106 107 108 |
# File 'lib/origami/trailer.rb', line 106 def dictionary @dictionary end |
#pdf ⇒ Object
Returns the value of attribute pdf.
104 105 106 |
# File 'lib/origami/trailer.rb', line 104 def pdf @pdf end |
#startxref ⇒ Object
Returns the value of attribute startxref.
105 106 107 |
# File 'lib/origami/trailer.rb', line 105 def startxref @startxref end |
Class Method Details
.parse(stream, parser = nil) ⇒ Object
:nodoc:
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/origami/trailer.rb', line 126 def self.parse(stream, parser = nil) #:nodoc: if stream.skip(@@regexp_open) dictionary = Dictionary.parse(stream, parser) 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
147 148 149 |
# File 'lib/origami/trailer.rb', line 147 def [](key) @dictionary[key] if has_dictionary? end |
#[]=(key, val) ⇒ Object
151 152 153 |
# File 'lib/origami/trailer.rb', line 151 def []=(key,val) @dictionary[key] = val end |
#has_dictionary? ⇒ Boolean
160 161 162 |
# File 'lib/origami/trailer.rb', line 160 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.
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/origami/trailer.rb', line 167 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 |