Module: Prawn::Document::Annotations

Included in:
Prawn::Document
Defined in:
lib/prawn/document/annotations.rb

Overview

Provides very low-level support for annotations. These extensions are mainly for use by prawn-format, so be sure to check that out if all you need is basic internal or external links.

Instance Method Summary collapse

Instance Method Details

#annotate(options) ⇒ Object

Adds a new annotation (section 8.4 in PDF spec) to the current page. options must be a Hash describing the annotation.


23
24
25
26
27
28
# File 'lib/prawn/document/annotations.rb', line 23

def annotate(options)
  current_page.data[:Annots] ||= []
  options = sanitize_annotation_hash(options)
  current_page.data[:Annots] << ref(options)
  return options
end

A convenience method for creating Link annotations. rect must be an array of four numbers, describing the bounds of the annotation. The options hash should include either :Dest (describing the target destination, usually as a string that has been recorded in the document's Dests tree), or :A (describing an action to perform on clicking the link), or :PA (for describing a URL to link to).


46
47
48
49
# File 'lib/prawn/document/annotations.rb', line 46

def link_annotation(rect, options={})
  options = options.merge(:Subtype => :Link, :Rect => rect)
  annotate(options)
end

#text_annotation(rect, contents, options = {}) ⇒ Object

A convenience method for creating Text annotations. rect must be an array of four numbers, describing the bounds of the annotation. contents should be a string, to be shown when the annotation is activated.


34
35
36
37
# File 'lib/prawn/document/annotations.rb', line 34

def text_annotation(rect, contents, options={})
  options = options.merge(:Subtype => :Text, :Rect => rect, :Contents => contents)
  annotate(options)
end