Module: PDF::Core::Destinations

Defined in:
lib/pdf/core/destinations.rb

Overview

:nodoc:

Constant Summary collapse

NAME_TREE_CHILDREN_LIMIT =

The maximum number of children to fit into a single node in the Dests tree.

20

Instance Method Summary collapse

Instance Method Details

#add_dest(name, reference) ⇒ Object

Adds a new destination to the dests name tree (see #dests). The reference parameter will be converted into a PDF::Core::Reference if it is not already one.



31
32
33
34
# File 'lib/pdf/core/destinations.rb', line 31

def add_dest(name, reference)
  reference = ref!(reference) unless reference.is_a?(PDF::Core::Reference)
  dests.data.add(name, reference)
end

#dest_fit(dest_page = page) ⇒ Object

Return a Dest specification that will fit the given page into the viewport.



46
47
48
# File 'lib/pdf/core/destinations.rb', line 46

def dest_fit(dest_page = page)
  [dest_page.dictionary, :Fit]
end

#dest_fit_bounds(dest_page = page) ⇒ Object

Return a Dest specfication that will fit the given page’s bounding box into the viewport.



74
75
76
# File 'lib/pdf/core/destinations.rb', line 74

def dest_fit_bounds(dest_page = page)
  [dest_page.dictionary, :FitB]
end

#dest_fit_bounds_horizontally(top, dest_page = page) ⇒ Object

Same as #dest_fit_horizontally, but works on the page’s bounding box instead of the entire page.



81
82
83
# File 'lib/pdf/core/destinations.rb', line 81

def dest_fit_bounds_horizontally(top, dest_page = page)
  [dest_page.dictionary, :FitBH, top]
end

#dest_fit_bounds_vertically(left, dest_page = page) ⇒ Object

Same as #dest_fit_vertically, but works on the page’s bounding box instead of the entire page.



88
89
90
# File 'lib/pdf/core/destinations.rb', line 88

def dest_fit_bounds_vertically(left, dest_page = page)
  [dest_page.dictionary, :FitBV, left]
end

#dest_fit_horizontally(top, dest_page = page) ⇒ Object

Return a Dest specification that will fit the given page horizontally into the viewport, aligned vertically at the given top coordinate.



53
54
55
# File 'lib/pdf/core/destinations.rb', line 53

def dest_fit_horizontally(top, dest_page = page)
  [dest_page.dictionary, :FitH, top]
end

#dest_fit_rect(left, bottom, right, top, dest_page = page) ⇒ Object

Return a Dest specification that will fit the given rectangle into the viewport, for the given page.



67
68
69
# File 'lib/pdf/core/destinations.rb', line 67

def dest_fit_rect(left, bottom, right, top, dest_page = page)
  [dest_page.dictionary, :FitR, left, bottom, right, top]
end

#dest_fit_vertically(left, dest_page = page) ⇒ Object

Return a Dest specification that will fit the given page vertically into the viewport, aligned horizontally at the given left coordinate.



60
61
62
# File 'lib/pdf/core/destinations.rb', line 60

def dest_fit_vertically(left, dest_page = page)
  [dest_page.dictionary, :FitV, left]
end

#dest_xyz(left, top, zoom = nil, dest_page = page) ⇒ Object

Return a Dest specification for a specific location (and optional zoom level).



39
40
41
# File 'lib/pdf/core/destinations.rb', line 39

def dest_xyz(left, top, zoom = nil, dest_page = page)
  [dest_page.dictionary, :XYZ, left, top, zoom]
end

#destsObject

The Dests name tree in the Name dictionary (see Prawn::Document::Internal#names). This name tree is used to store named destinations (PDF spec 8.2.1). (For more on name trees, see section 3.8.4 in the PDF spec.)



21
22
23
24
25
# File 'lib/pdf/core/destinations.rb', line 21

def dests
  names.data[:Dests] ||= ref!(
    PDF::Core::NameTree::Node.new(self, NAME_TREE_CHILDREN_LIMIT)
  )
end