Class: PDF::Writer::Object::Outline

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

Overview

Define the outlines in the doc, empty for now

Instance Attribute Summary

Attributes inherited from PDF::Writer::Object

#oid

Instance Method Summary collapse

Constructor Details

#initialize(parent, label, title = label) ⇒ Outline

Returns a new instance of Outline.



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

def initialize(parent, label, title = label)
  super(parent)

  @action = PDF::Writer::Action.new(parent, label, :ilink)
  @title  = title

  parent.outlines.list << self
end

Instance Method Details

#to_sObject



22
23
24
25
26
27
28
29
# File 'lib/gems/pdf-writer-1.1.8/lib/pdf/writer/object/outline.rb', line 22

def to_s
  pos = @parent.outlines.list.index(self)
  res = "\n#{@oid} 0 obj\n<< /Title (#{@title})"
  res << " /Prev #{@parent.outlines.list[pos - 1].oid} 0 R" if pos.nonzero?
  res << " /Next #{@parent.outlines.list[pos + 1].oid} 0 R" if @oid != parent.outlines.list[-1].oid
  res << " /A #{@action.oid} 0 R>>\nendobj"
  res
end