Class: PDF::Writer::Object::Annotation

Inherits:
PDF::Writer::Object show all
Defined in:
lib/pdf/writer/object/annotation.rb

Overview

An annotation object, this will add an annotation to the current page. initially will support just link annotations.

Constant Summary collapse

TYPES =
[:link, :ilink]

Instance Attribute Summary collapse

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

Constructor Details

#initialize(parent, type, rect, label) ⇒ Annotation

Returns a new instance of Annotation


16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/pdf/writer/object/annotation.rb', line 16

def initialize(parent, type, rect, label)
  super(parent)

  @type = type
  @rect = rect

  case @type
  when :link
    @action = PDF::Writer::Object::Action.new(parent, label)
  when :ilink
    @action = PDF::Writer::Object::Action.new(parent, label, type)
  end
  parent.current_page.add_annotation(self)
end

Instance Attribute Details

#actionObject

Returns the value of attribute action


32
33
34
# File 'lib/pdf/writer/object/annotation.rb', line 32

def action
  @action
end

#rectObject

Returns the value of attribute rect


33
34
35
# File 'lib/pdf/writer/object/annotation.rb', line 33

def rect
  @rect
end

#typeObject

Returns the value of attribute type


31
32
33
# File 'lib/pdf/writer/object/annotation.rb', line 31

def type
  @type
end

Instance Method Details

#to_sObject


35
36
37
38
39
40
41
# File 'lib/pdf/writer/object/annotation.rb', line 35

def to_s
  res = "\n#{@oid} 0 obj\n<< /Type /Annot"
  res << "\n/Subtype /Link" if TYPES.include?(@type)
  res << "\n/A #{@action.oid} 0 R\n/Border [0 0 0]\n/H /I\n/Rect ["
  @rect.each { |v| res << "%.4f " % v }
  res << "]\n>>\nendobj"
end