Class: PDF::Writer::Object::Contents
- Inherits:
-
PDF::Writer::Object
- Object
- PDF::Writer::Object
- PDF::Writer::Object::Contents
- Defined in:
- lib/extensions/pdf-writer/pdf/writer/object/contents.rb
Overview
The contents objects hold all of the content which appears on pages
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#on_page ⇒ Object
readonly
Returns the value of attribute on_page.
Attributes inherited from PDF::Writer::Object
Instance Method Summary collapse
- #<<(v) ⇒ Object
- #add(a) ⇒ Object
- #each ⇒ Object
-
#initialize(parent, page = nil) ⇒ Contents
constructor
A new instance of Contents.
- #size ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(parent, page = nil) ⇒ Contents
Returns a new instance of Contents.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 13 def initialize(parent, page = nil) super(parent) @data = "" @info = {} @raw = false @on_page = nil if page.kind_of?(PDF::Writer::Object::Page) @on_page = page elsif page == :raw @raw = true end end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
29 30 31 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 29 def data @data end |
#on_page ⇒ Object (readonly)
Returns the value of attribute on_page.
28 29 30 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 28 def on_page @on_page end |
Instance Method Details
#<<(v) ⇒ Object
39 40 41 42 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 39 def <<(v) raise TypeError unless v.kind_of?(PDF::Writer::Object) or v.kind_of?(String) @data << v end |
#add(a) ⇒ Object
44 45 46 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 44 def add(a) a.each { |k, v| @info[k] = v } end |
#each ⇒ Object
35 36 37 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 35 def each @contents.each { |c| yield c } end |
#size ⇒ Object
31 32 33 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 31 def size @data.size end |
#to_s ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/extensions/pdf-writer/pdf/writer/object/contents.rb', line 48 def to_s tmp = @data.dup res = "\n#{@oid} 0 obj\n" if @raw res << tmp else res << "<<" if PDF::Writer::Compression and @parent.compressed? res << " /Filter /FlateDecode" tmp = Zlib::Deflate.deflate(tmp) end @info.each { |k, v| res << "\n/#{k} #{v}" } res << "\n/Length #{tmp.size} >>\nstream\n#{tmp}\nendstream" end res << "\nendobj\n" res end |