Class: Pdfrb::Document::Annotations

Inherits:
Object
  • Object
show all
Defined in:
lib/pdfrb/document/annotations.rb

Overview

Annotations facade (stub). Full implementation in TODO 131.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document) ⇒ Annotations

Returns a new instance of Annotations.



9
10
11
# File 'lib/pdfrb/document/annotations.rb', line 9

def initialize(document)
  @document = document
end

Instance Attribute Details

#documentObject (readonly)

Returns the value of attribute document.



7
8
9
# File 'lib/pdfrb/document/annotations.rb', line 7

def document
  @document
end

Instance Method Details

#add(page, subtype:, rect:, **opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/pdfrb/document/annotations.rb', line 13

def add(page, subtype:, rect:, **opts)
  annot = document.add(
    {
      Type: :Annot,
      Subtype: subtype,
      Rect: rect,
      P: Pdfrb::Model::Reference.new(page.oid, page.gen),
      Contents: opts[:contents],
      F: opts[:flags] || 0
    }.compact,
    type: Pdfrb::Model::Type::Annotation
  )
  annots = (page.value[:Annots] ||= [])
  annots << Pdfrb::Model::Reference.new(annot.oid, annot.gen)
  annot
end

#each(page) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pdfrb/document/annotations.rb', line 30

def each(page)
  return enum_for(:each, page) unless block_given?

  annots = page.value[:Annots]
  return self unless annots

  annots.each do |ref|
    a = ref.is_a?(Pdfrb::Model::Reference) ? document.object(ref) : ref
    yield a if a
  end
  self
end