Class: PDF::Writer::Object::Contents

Inherits:
PDF::Writer::Object show all
Defined in:
lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb

Overview

The contents objects hold all of the content which appears on pages

Instance Attribute Summary collapse

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

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/gems/pdf-writer-1.1.8/lib/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

#dataObject

Returns the value of attribute data.



29
30
31
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb', line 29

def data
  @data
end

#on_pageObject (readonly)

Returns the value of attribute on_page.



28
29
30
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb', line 28

def on_page
  @on_page
end

Instance Method Details

#<<(v) ⇒ Object

Raises:

  • (TypeError)


39
40
41
42
# File 'lib/gems/pdf-writer-1.1.8/lib/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/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb', line 44

def add(a)
  a.each { |k, v| @info[k] = v }
end

#eachObject



35
36
37
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb', line 35

def each
  @contents.each { |c| yield c }
end

#sizeObject



31
32
33
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/contents.rb', line 31

def size
  @data.size
end

#to_sObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/gems/pdf-writer-1.1.8/lib/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