7 * This source file is subject to the new BSD license that is bundled
8 * with this package in the file LICENSE.txt.
9 * It is also available through the world-wide-web at this URL:
10 * http://framework.zend.com/license/new-bsd
11 * If you did not receive a copy of the license and are unable to
12 * obtain it through the world-wide-web, please send an email
13 * to license@zend.com so we can send you a copy immediately.
17 * @subpackage Annotation
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
23 /** Zend_Pdf_Annotation */
24 require_once 'Zend/Pdf/Annotation.php';
26 /** Zend_Pdf_Destination */
27 require_once 'Zend/Pdf/Destination.php';
31 * A link annotation represents either a hypertext link to a destination elsewhere in
32 * the document or an action to be performed.
34 * Only destinations are used now since only GoTo action can be created by user
35 * in current implementation.
38 * @subpackage Annotation
39 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
40 * @license http://framework.zend.com/license/new-bsd New BSD License
42 class Zend_Pdf_Annotation_Link
extends Zend_Pdf_Annotation
45 * Annotation object constructor
47 * @throws Zend_Pdf_Exception
49 public function __construct(Zend_Pdf_Element
$annotationDictionary)
51 if ($annotationDictionary->getType() != Zend_Pdf_Element
::TYPE_DICTIONARY
) {
52 require_once 'Zend/Pdf/Exception.php';
53 throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
56 if ($annotationDictionary->Subtype
=== null ||
57 $annotationDictionary->Subtype
->getType() != Zend_Pdf_Element
::TYPE_NAME ||
58 $annotationDictionary->Subtype
->value
!= 'Link') {
59 require_once 'Zend/Pdf/Exception.php';
60 throw new Zend_Pdf_Exception('Subtype => Link entry is requires');
63 parent
::__construct($annotationDictionary);
67 * Create link annotation object
73 * @param Zend_Pdf_Target|string $target
74 * @return Zend_Pdf_Annotation_Link
76 public static function create($x1, $y1, $x2, $y2, $target)
78 if (is_string($target)) {
79 require_once 'Zend/Pdf/Destination/Named.php';
80 $destination = Zend_Pdf_Destination_Named
::create($target);
82 if (!$target instanceof Zend_Pdf_Target
) {
83 require_once 'Zend/Pdf/Exception.php';
84 throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
87 $annotationDictionary = new Zend_Pdf_Element_Dictionary();
89 $annotationDictionary->Type
= new Zend_Pdf_Element_Name('Annot');
90 $annotationDictionary->Subtype
= new Zend_Pdf_Element_Name('Link');
92 $rectangle = new Zend_Pdf_Element_Array();
93 $rectangle->items
[] = new Zend_Pdf_Element_Numeric($x1);
94 $rectangle->items
[] = new Zend_Pdf_Element_Numeric($y1);
95 $rectangle->items
[] = new Zend_Pdf_Element_Numeric($x2);
96 $rectangle->items
[] = new Zend_Pdf_Element_Numeric($y2);
97 $annotationDictionary->Rect
= $rectangle;
99 if ($target instanceof Zend_Pdf_Destination
) {
100 $annotationDictionary->Dest
= $target->getResource();
102 $annotationDictionary->A
= $target->getResource();
105 return new Zend_Pdf_Annotation_Link($annotationDictionary);
109 * Set link annotation destination
111 * @param Zend_Pdf_Target|string $target
112 * @return Zend_Pdf_Annotation_Link
114 public function setDestination($target)
116 if (is_string($target)) {
117 require_once 'Zend/Pdf/Destination/Named.php';
118 $destination = Zend_Pdf_Destination_Named
::create($target);
120 if (!$target instanceof Zend_Pdf_Target
) {
121 require_once 'Zend/Pdf/Exception.php';
122 throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
125 $this->_annotationDictionary
->touch();
126 $this->_annotationDictionary
->Dest
= $destination->getResource();
127 if ($target instanceof Zend_Pdf_Destination
) {
128 $this->_annotationDictionary
->Dest
= $target->getResource();
129 $this->_annotationDictionary
->A
= null;
131 $this->_annotationDictionary
->Dest
= null;
132 $this->_annotationDictionary
->A
= $target->getResource();
139 * Get link annotation destination
141 * @return Zend_Pdf_Target|null
143 public function getDestination()
145 if ($this->_annotationDictionary
->Dest
=== null &&
146 $this->_annotationDictionary
->A
=== null) {
150 if ($this->_annotationDictionary
->Dest
!== null) {
151 return Zend_Pdf_Destination
::load($this->_annotationDictionary
->Dest
);
153 return Zend_Pdf_Action
::load($this->_annotationDictionary
->A
);