Bladeren bron

Zend_Pdf: ZF-5832, ZF-6911, ZF-6914, ZF-6915 related commit.

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17244 44c647ce-9c0f-0410-b52a-842ac1e357ba
alexander 16 jaren geleden
bovenliggende
commit
0cd845a240

+ 225 - 99
documentation/manual/en/module_specs/Zend_Pdf-InteractiveFeatures.xml

@@ -918,123 +918,125 @@ $pdf->save($path, true);
         
         <para>
             Outline attributes may be retrieved or set using the following methods:
-            <itemizedlist>
-                <listitem>
-                    <para>
-                        <methodname>string getTitle()</methodname> - get outline item title.
-                    </para>
-                </listitem>
+        </para>
 
-                <listitem>
-                    <para>
-                        <methodname>setTitle(string $title)</methodname> - set outline item title.
-                    </para>
-                </listitem>
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <methodname>string getTitle()</methodname> - get outline item title.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>boolean isOpen()</methodname> - true if outline is open 
-                        by default.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setTitle(string $title)</methodname> - set outline item title.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setIsOpen(boolean $isOpen)</methodname> - set isOpen state.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>boolean isOpen()</methodname> - true if outline is open 
+                    by default.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>boolean isItalic()</methodname> - true if outline item 
-                        is displayed in italic.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setIsOpen(boolean $isOpen)</methodname> - set isOpen state.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setIsItalic(boolean $isItalic)</methodname> - set 
-                        isItalic state.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>boolean isItalic()</methodname> - true if outline item 
+                    is displayed in italic.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>boolean isBold()</methodname> - true if outline item 
-                        is displayed in bold.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setIsItalic(boolean $isItalic)</methodname> - set 
+                    isItalic state.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setIsBold(boolean $isBold)</methodname> - set 
-                        isBold state.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>boolean isBold()</methodname> - true if outline item 
+                    is displayed in bold.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>Zend_Pdf_Color_Rgb getColor()</methodname> - get outline 
-                        text color (null means black).
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setIsBold(boolean $isBold)</methodname> - set 
+                    isBold state.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setColor(Zend_Pdf_Color_Rgb $color)</methodname> - set 
-                        outline text color (null means black).
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Color_Rgb getColor()</methodname> - get outline 
+                    text color (null means black).
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>Zend_Pdf_Target getTarget()</methodname> - get outline 
-                        target (action or explicit or named destination object).
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setColor(Zend_Pdf_Color_Rgb $color)</methodname> - set 
+                    outline text color (null means black).
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setTarget(Zend_Pdf_Target|string $target)</methodname> - set 
-                        outline target (action or destination). String may be used to identify
-                        named destination. Null means 'no target'.
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Target getTarget()</methodname> - get outline 
+                    target (action or explicit or named destination object).
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>array getOptions()</methodname> - get outline attributes 
-                        as an array. 
-                    </para>
-                </listitem>
+            <listitem>
+                <para>
+                    <methodname>setTarget(Zend_Pdf_Target|string $target)</methodname> - set 
+                    outline target (action or destination). String may be used to identify
+                    named destination. Null means 'no target'.
+                </para>
+            </listitem>
 
-                <listitem>
-                    <para>
-                        <methodname>setOptions(array $options)</methodname> - set outline options. 
-                        The following options are recognized: 'title', 'open', 'color', 'italic',
-                        'bold', and 'target'.
-                    </para>
-                </listitem>
-            </itemizedlist>
-        </para>
+            <listitem>
+                <para>
+                    <methodname>array getOptions()</methodname> - get outline attributes 
+                    as an array. 
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    <methodname>setOptions(array $options)</methodname> - set outline options. 
+                    The following options are recognized: 'title', 'open', 'color', 'italic',
+                    'bold', and 'target'.
+                </para>
+            </listitem>
+        </itemizedlist>
 
         <para>
             New outline may be created in two ways:        
-            <itemizedlist>
-                <listitem>
-                    <para>
-                        <methodname>Zend_Pdf_Outline::create(string $title[, Zend_Pdf_Target|string $target])</methodname>
-                    </para>
-                </listitem>
-
-                <listitem>
-                    <para>
-                        <methodname>Zend_Pdf_Outline::create(array $options)</methodname>
-                    </para>
-                </listitem>
-            </itemizedlist>
         </para>
 
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Outline::create(string $title[, Zend_Pdf_Target|string $target])</methodname>
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Outline::create(array $options)</methodname>
+                </para>
+            </listitem>
+        </itemizedlist>
+
         <para>
             Each outline object may have child outline items listed in 
             <varname>Zend_Pdf_Outline::$childOutlines</varname> public property.
@@ -1082,8 +1084,132 @@ $pdf->save($path, true);
 
     <sect2 id="zend.pdf.pages.interactive-features.annotations">
         <title>Annotations</title>
+        
+        <para>
+            An annotation associates an object such as a note, sound, or movie with a location 
+            on a page of a PDF document, or provides a way to interact with the user by means 
+            of the mouse and keyboard.
+        </para>
+        
+        <para>
+            All annotations are represented by <classname>Zend_Pdf_Annotation</classname> 
+            abstract class.
+        </para>
+
+        <para>
+            Annotation may be attached to a page using 
+            <methodname>Zend_Pdf_Page::attachAnnotation(Zend_Pdf_Annotation $annotation)</methodname>
+            method.
+        </para>
+
         <para>
+            Three types of annotations may be created by user now:
         </para>
+        
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Annotation_Link::create($x1, $y1, $x2, $y2, $target)</methodname>
+                    where <varname>$target</varname> is an action object or a destination or 
+                    string (which may be used in place of named destination object).
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Annotation_Text::create($x1, $y1, $x2, $y2, $text)</methodname>
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Annotation_FileAttachment::create($x1, $y1, $x2, $y2, $fileSpecification)</methodname>
+                </para>
+            </listitem>
+        </itemizedlist>
+        
+        <para>
+            A link annotation represents either a hypertext link to a destination elsewhere in 
+            the document or an action to be performed.
+        </para>
+        
+        <para>
+            A text annotation represents a "sticky note" attached to a point in the PDF document.
+        </para>
+        
+        <para>
+            A file attachment annotation contains a reference to a file.
+        </para>
+        
+        <para>
+            The following methods are shared between all annotation types:
+        </para>
+
+        <itemizedlist>
+            <listitem>
+                <para><methodname>setLeft(float $left)</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>float getLeft()</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>setRight(float $right)</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>float getRight()</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>setTop(float $top)</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>float getTop()</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>setBottom(float $bottom)</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>float getBottom()</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>setText(string $text)</methodname></para>
+            </listitem>
+
+            <listitem>
+                <para><methodname>string getText()</methodname></para>
+            </listitem>
+        </itemizedlist>
+        
+        <para>
+            Text annotation property is a text to be displayed for the annotation or, if this 
+            type of annotation does not display text, an alternate description of the annotation’s 
+            contents in human-readable form.
+        </para>
+
+        <para>
+            Link annotation objects also provide two additional methods:
+        </para>
+   
+        <itemizedlist>
+            <listitem>
+                <para>
+                    <methodname>setDestination(Zend_Pdf_Target|string $target)</methodname>
+                </para>
+            </listitem>
+
+            <listitem>
+                <para>
+                    <methodname>Zend_Pdf_Target getDestination()</methodname>
+                </para>
+            </listitem>
+        </itemizedlist>
     </sect2>
 </sect1>
 <!--

+ 1 - 1
library/Zend/Pdf/Action/GoTo.php

@@ -89,7 +89,7 @@ class Zend_Pdf_Action_GoTo extends Zend_Pdf_Action
     /**
      * Set goto action destination
      *
-     * @return Zend_Pdf_Action_GoTo $destination
+     * @return Zend_Pdf_Action_GoTo
      */
     public function setDestination(Zend_Pdf_Destination $destination)
     {

+ 229 - 0
library/Zend/Pdf/Annotation.php

@@ -0,0 +1,229 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id:
+ */
+
+/** Zend_Pdf_ElementFactory */
+require_once 'Zend/Pdf/ElementFactory.php';
+
+
+/**
+ * Abstract PDF annotation representation class
+ *
+ * An annotation associates an object such as a note, sound, or movie with a location
+ * on a page of a PDF document, or provides a way to interact with the user by
+ * means of the mouse and keyboard.
+ *
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+abstract class Zend_Pdf_Annotation
+{
+	/**
+	 * Annotation dictionary
+	 *
+	 * @var Zend_Pdf_Element_Dictionary|Zend_Pdf_Element_Object|Zend_Pdf_Element_Reference
+	 */
+	protected $_annotationDictionary;
+
+	/**
+	 * Get annotation dictionary
+	 *
+	 * @internal
+	 * @return Zend_Pdf_Element
+	 */
+	public function getResource()
+	{
+		return $this->_annotationDictionary;
+	}
+
+
+	/**
+	 * Set bottom edge of the annotation rectangle.
+	 *
+	 * @param float $bottom
+	 * @return Zend_Pdf_Annotation
+	 */
+	public function setBottom($bottom) {
+		$this->_annotationDictionary->Rect->items[1]->touch();
+		$this->_annotationDictionary->Rect->items[1]->value = $bottom;
+
+        return $this;
+	}
+
+	/**
+	 * Get bottom edge of the annotation rectangle.
+	 *
+	 * @return float
+	 */
+	public function getBottom() {
+		return $this->_annotationDictionary->Rect->items[1]->value;
+	}
+
+	/**
+	 * Set top edge of the annotation rectangle.
+	 *
+	 * @param float $top
+     * @return Zend_Pdf_Annotation
+	 */
+	public function setTop($top) {
+        $this->_annotationDictionary->Rect->items[3]->touch();
+        $this->_annotationDictionary->Rect->items[3]->value = $top;
+
+        return $this;
+	}
+
+	/**
+	 * Get top edge of the annotation rectangle.
+	 *
+	 * @return float
+	 */
+	public function getTop() {
+		return $this->_annotationDictionary->Rect->items[3]->value;
+	}
+
+	/**
+	 * Set right edge of the annotation rectangle.
+	 *
+	 * @param float $right
+     * @return Zend_Pdf_Annotation
+	 */
+	public function setRight($right) {
+        $this->_annotationDictionary->Rect->items[2]->touch();
+        $this->_annotationDictionary->Rect->items[2]->value = $right;
+
+        return $this;
+	}
+
+	/**
+	 * Get right edge of the annotation rectangle.
+	 *
+	 * @return float
+	 */
+	public function getRight() {
+		return $this->_annotationDictionary->Rect->items[2]->value;
+	}
+
+	/**
+	 * Set left edge of the annotation rectangle.
+	 *
+	 * @param float $left
+     * @return Zend_Pdf_Annotation
+	 */
+	public function setLeft($left) {
+        $this->_annotationDictionary->Rect->items[0]->touch();
+        $this->_annotationDictionary->Rect->items[0]->value = $left;
+
+		return $this;
+	}
+
+	/**
+	 * Get left edge of the annotation rectangle.
+	 *
+	 * @return float
+	 */
+	public function getLeft() {
+		return $this->_annotationDictionary->Rect->items[0]->value;
+	}
+
+    /**
+     * Return text to be displayed for the annotation or, if this type of annotation
+     * does not display text, an alternate description of the annotation’s contents
+     * in human-readable form.
+     *
+     * @return string
+     */
+    public function getText() {
+    	if ($this->_annotationDictionary->Contents === null) {
+    		return '';
+    	}
+
+        return $this->_annotationDictionary->Contents->value;
+    }
+
+    /**
+     * Set text to be displayed for the annotation or, if this type of annotation
+     * does not display text, an alternate description of the annotation’s contents
+     * in human-readable form.
+     *
+     * @param string $text
+     * @return Zend_Pdf_Annotation
+     */
+    public function setText($text) {
+        if ($this->_annotationDictionary->Contents === null) {
+        	$this->_annotationDictionary->touch();
+            $this->_annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
+        } else {
+        	$this->_annotationDictionary->Contents->touch();
+        	$this->_annotationDictionary->Contents->value = new Zend_Pdf_Element_String($text);
+        }
+
+        return $this;
+    }
+
+    /**
+	 * Annotation object constructor
+	 *
+	 * @throws Zend_Pdf_Exception
+	 */
+	public function __construct(Zend_Pdf_Element $annotationDictionary)
+	{
+        if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
+        }
+
+        $this->_annotationDictionary = $annotationDictionary;
+
+        if ($this->_annotationDictionary->Type !== null  &&
+            $this->_annotationDictionary->Type->value != 'Annot') {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Wrong resource type. \'Annot\' expected.');
+        }
+
+        if ($this->_annotationDictionary->Rect === null) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('\'Rect\' dictionary entry is required.');
+        }
+
+        if (count($this->_annotationDictionary->Rect->items) != 4 ||
+            $this->_annotationDictionary->Rect->items[0]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
+            $this->_annotationDictionary->Rect->items[1]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
+            $this->_annotationDictionary->Rect->items[2]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ||
+            $this->_annotationDictionary->Rect->items[3]->getType() != Zend_Pdf_Element::TYPE_NUMERIC ) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('\'Rect\' dictionary entry must be an array of four numeric elements.');
+        }
+	}
+
+    /**
+     * Load Annotation object from a specified resource
+     *
+     * @internal
+     * @param $destinationArray
+     * @return Zend_Pdf_Destination
+     */
+    public static function load(Zend_Pdf_Element $resource)
+    {
+    	/** @todo implementation */
+    }
+}

+ 93 - 0
library/Zend/Pdf/Annotation/FileAttachment.php

@@ -0,0 +1,93 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id:
+ */
+
+/** Zend_Pdf_Annotation */
+require_once 'Zend/Pdf/Annotation.php';
+
+
+/**
+ * A file attachment annotation contains a reference to a file,
+ * which typically is embedded in the PDF file.
+ *
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Pdf_Annotation_FileAttachment extends Zend_Pdf_Annotation
+{
+    /**
+     * Annotation object constructor
+     *
+     * @throws Zend_Pdf_Exception
+     */
+    public function __construct(Zend_Pdf_Element $annotationDictionary)
+    {
+        if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
+        }
+
+        if ($annotationDictionary->Subtype === null  ||
+            $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
+            $annotationDictionary->Subtype->value != 'FileAttachment') {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Subtype => FileAttachment entry is requires');
+        }
+
+        parent::__construct($annotationDictionary);
+    }
+
+    /**
+     * Create link annotation object
+     *
+     * @param float $x1
+     * @param float $y1
+     * @param float $x2
+     * @param float $y2
+     * @param string $fileSpecification
+     * @return Zend_Pdf_Annotation_FileAttachment
+     */
+    public static function create($x1, $y1, $x2, $y2, $fileSpecification)
+    {
+        $annotationDictionary = new Zend_Pdf_Element_Dictionary();
+
+        $annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
+        $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('FileAttachment');
+
+        $rectangle = new Zend_Pdf_Element_Array();
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
+        $annotationDictionary->Rect = $rectangle;
+
+        $fsDictionary = new Zend_Pdf_Element_Dictionary();
+        $fsDictionary->Type = new Zend_Pdf_Element_Name('Filespec');
+        $fsDictionary->F    = new Zend_Pdf_Element_String($fileSpecification);
+
+        $annotationDictionary->FS = $fsDictionary;
+
+
+        return new Zend_Pdf_Annotation_FileAttachment($annotationDictionary);
+    }
+}

+ 156 - 0
library/Zend/Pdf/Annotation/Link.php

@@ -0,0 +1,156 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id:
+ */
+
+/** Zend_Pdf_Annotation */
+require_once 'Zend/Pdf/Annotation.php';
+
+/** Zend_Pdf_Destination */
+require_once 'Zend/Pdf/Destination.php';
+
+
+/**
+ * A link annotation represents either a hypertext link to a destination elsewhere in
+ * the document or an action to be performed.
+ *
+ * Only destinations are used now since only GoTo action can be created by user
+ * in current implementation.
+ *
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Pdf_Annotation_Link extends Zend_Pdf_Annotation
+{
+    /**
+     * Annotation object constructor
+     *
+     * @throws Zend_Pdf_Exception
+     */
+    public function __construct(Zend_Pdf_Element $annotationDictionary)
+    {
+        if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
+        }
+
+        if ($annotationDictionary->Subtype === null  ||
+            $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
+            $annotationDictionary->Subtype->value != 'Link') {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Subtype => Link entry is requires');
+        }
+
+        parent::__construct($annotationDictionary);
+    }
+
+    /**
+     * Create link annotation object
+     *
+     * @param float $x1
+     * @param float $y1
+     * @param float $x2
+     * @param float $y2
+     * @param Zend_Pdf_Target|string $target
+     * @return Zend_Pdf_Annotation_Link
+     */
+    public static function create($x1, $y1, $x2, $y2, $target)
+    {
+        if (is_string($target)) {
+            require_once 'Zend/Pdf/Destination/Named.php';
+            $destination = Zend_Pdf_Destination_Named::create($target);
+        }
+        if (!$target instanceof Zend_Pdf_Target) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
+        }
+
+    	$annotationDictionary = new Zend_Pdf_Element_Dictionary();
+
+    	$annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
+    	$annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Link');
+
+    	$rectangle = new Zend_Pdf_Element_Array();
+    	$rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
+    	$rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
+    	$rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
+    	$rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
+    	$annotationDictionary->Rect = $rectangle;
+
+    	if ($target instanceof Zend_Pdf_Destination) {
+            $annotationDictionary->Dest = $target->getResource();
+    	} else {
+            $annotationDictionary->A = $target->getResource();
+    	}
+
+        return new Zend_Pdf_Annotation_Link($annotationDictionary);
+    }
+
+    /**
+     * Set link annotation destination
+     *
+     * @param Zend_Pdf_Target|string $target
+     * @return Zend_Pdf_Annotation_Link
+     */
+    public function setDestination($target)
+    {
+        if (is_string($target)) {
+            require_once 'Zend/Pdf/Destination/Named.php';
+            $destination = Zend_Pdf_Destination_Named::create($target);
+        }
+        if (!$target instanceof Zend_Pdf_Target) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('$target parameter must be a Zend_Pdf_Target object or a string.');
+        }
+
+        $this->_annotationDictionary->touch();
+        $this->_annotationDictionary->Dest = $destination->getResource();
+        if ($target instanceof Zend_Pdf_Destination) {
+            $this->_annotationDictionary->Dest = $target->getResource();
+            $this->_annotationDictionary->A    = null;
+        } else {
+            $this->_annotationDictionary->Dest = null;
+            $this->_annotationDictionary->A    = $target->getResource();
+        }
+
+        return $this;
+    }
+
+    /**
+     * Get link annotation destination
+     *
+     * @return Zend_Pdf_Target|null
+     */
+    public function getDestination()
+    {
+    	if ($this->_annotationDictionary->Dest === null  &&
+    	    $this->_annotationDictionary->A    === null) {
+    		return null;
+    	}
+
+        if ($this->_annotationDictionary->Dest !== null) {
+        	return Zend_Pdf_Destination::load($this->_annotationDictionary->Dest);
+        } else {
+        	return Zend_Pdf_Action::load($this->_annotationDictionary->A);
+        }
+    }
+}

+ 87 - 0
library/Zend/Pdf/Annotation/Text.php

@@ -0,0 +1,87 @@
+<?php
+/**
+ * Zend Framework
+ *
+ * LICENSE
+ *
+ * This source file is subject to the new BSD license that is bundled
+ * with this package in the file LICENSE.txt.
+ * It is also available through the world-wide-web at this URL:
+ * http://framework.zend.com/license/new-bsd
+ * If you did not receive a copy of the license and are unable to
+ * obtain it through the world-wide-web, please send an email
+ * to license@zend.com so we can send you a copy immediately.
+ *
+ * @category   Zend
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ * @version    $Id:
+ */
+
+/** Zend_Pdf_Annotation */
+require_once 'Zend/Pdf/Annotation.php';
+
+
+/**
+ * A text annotation represents a "sticky note" attached to a point in the PDF document.
+ *
+ * @package    Zend_Pdf
+ * @subpackage Annotation
+ * @copyright  Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
+ * @license    http://framework.zend.com/license/new-bsd     New BSD License
+ */
+class Zend_Pdf_Annotation_Text extends Zend_Pdf_Annotation
+{
+    /**
+     * Annotation object constructor
+     *
+     * @throws Zend_Pdf_Exception
+     */
+    public function __construct(Zend_Pdf_Element $annotationDictionary)
+    {
+        if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
+        }
+
+        if ($annotationDictionary->Subtype === null  ||
+            $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
+            $annotationDictionary->Subtype->value != 'Text') {
+            require_once 'Zend/Pdf/Exception.php';
+            throw new Zend_Pdf_Exception('Subtype => Text entry is requires');
+        }
+
+        parent::__construct($annotationDictionary);
+    }
+
+    /**
+     * Create link annotation object
+     *
+     * @param float $x1
+     * @param float $y1
+     * @param float $x2
+     * @param float $y2
+     * @param string $text
+     * @return Zend_Pdf_Annotation_Text
+     */
+    public static function create($x1, $y1, $x2, $y2, $text)
+    {
+        $annotationDictionary = new Zend_Pdf_Element_Dictionary();
+
+        $annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
+        $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('Text');
+
+        $rectangle = new Zend_Pdf_Element_Array();
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
+        $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
+        $annotationDictionary->Rect = $rectangle;
+
+        $annotationDictionary->Contents = new Zend_Pdf_Element_String($text);
+
+        return new Zend_Pdf_Annotation_Text($annotationDictionary);
+    }
+}

+ 31 - 0
library/Zend/Pdf/Page.php

@@ -46,6 +46,9 @@ require_once 'Zend/Pdf/Color/Rgb.php';
 /** Zend_Pdf_Color_Cmyk */
 require_once 'Zend/Pdf/Color/Cmyk.php';
 
+/** Zend_Pdf_Annotation */
+require_once 'Zend/Pdf/Annotation.php';
+
 /**
  * PDF Page
  *
@@ -1439,6 +1442,34 @@ class Zend_Pdf_Page
     }
 
     /**
+     *
+     * @param Zend_Pdf_Annotation $annotation
+     * @return Zend_Pdf_Page
+     */
+    public function attachAnnotation(Zend_Pdf_Annotation $annotation)
+    {
+        $annotationDictionary = $annotation->getResource();
+        if (!$annotationDictionary instanceof Zend_Pdf_Element_Object  &&
+            !$annotationDictionary instanceof Zend_Pdf_Element_Reference) {
+            $annotationDictionary = $this->_objFactory->newObject($annotationDictionary);
+        }
+
+        if ($this->_pageDictionary->Annots === null) {
+    		$this->_pageDictionary->touch();
+    		$this->_pageDictionary->Annots = new Zend_Pdf_Element_Array();
+    	} else {
+    		$this->_pageDictionary->Annots->touch();
+    	}
+
+    	$this->_pageDictionary->Annots->items[] = $annotationDictionary;
+
+        $annotationDictionary->touch();
+        $annotationDictionary->P = $this->_pageDictionary;
+
+        return $this;
+    }
+
+    /**
      * Return the height of this page in points.
      *
      * @return float