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 + "(?<startxref>\\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.
-
#document ⇒ Object
Returns the value of attribute document.
-
#startxref ⇒ Object
Returns the value of attribute startxref.
Class Method Summary collapse
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #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
included, #pre_build, #version_required
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 |
# 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 |
#document ⇒ Object
Returns the value of attribute document.
96 97 98 |
# File 'lib/origami/trailer.rb', line 96 def document @document 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, parser = nil) ⇒ Object
:nodoc:
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/origami/trailer.rb', line 117 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['startxref'].to_i if not stream.scan(@@regexp_close) parser.warn("No %%EOF token found") if parser end Trailer.new(startxref, dictionary) end |
Instance Method Details
#[](key) ⇒ Object
138 139 140 |
# File 'lib/origami/trailer.rb', line 138 def [](key) @dictionary[key] if dictionary? end |
#[]=(key, val) ⇒ Object
142 143 144 145 |
# File 'lib/origami/trailer.rb', line 142 def []=(key,val) self.dictionary = Dictionary.new unless dictionary? @dictionary[key] = val end |
#dictionary? ⇒ Boolean
152 153 154 |
# File 'lib/origami/trailer.rb', line 152 def dictionary? not @dictionary.nil? end |
#to_obfuscated_str ⇒ Object
233 234 235 236 237 238 239 240 241 242 |
# File 'lib/origami/obfuscation.rb', line 233 def content = "" if self.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 |
# File 'lib/origami/trailer.rb', line 159 def to_s content = "" if self.dictionary? content << TOKENS.first << EOL << @dictionary.to_s << EOL end content << XREF_TOKEN << EOL << @startxref.to_s << EOL << TOKENS.last << EOL content end |