Class: PDF::Writer::Object::Action

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

Overview

An action object, used to link to URLS initially

Instance Attribute Summary collapse

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

Constructor Details

#initialize(parent, label, type = "URI") ⇒ Action

Returns a new instance of Action.

Raises:

  • (TypeError)


13
14
15
16
17
18
19
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb', line 13

def initialize(parent, label, type = "URI")
  super(parent)

  @type   = type
  @label  = label
  raise TypeError if @label.nil?
end

Instance Attribute Details

#labelObject

Returns the value of attribute label.



22
23
24
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb', line 22

def label
  @label
end

#typeObject

Returns the value of attribute type.



21
22
23
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb', line 21

def type
  @type
end

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/action.rb', line 24

def to_s
  res = "\n#{@oid} 0 obj\n<< /Type /Action"
  if @type == :ilink
    res << "\n/S /GoTo\n/D #{@parent.destinations[@label].oid} 0 R"
  elsif @type == 'URI'
    res << "\n/S /URI\n/URI ("
    res << PDF::Writer.escape(@label)
    res << ")\n"
  end
  res << ">>\nendobj"
end