File indexing completed on 2024-12-22 05:36:53

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Pdf
0017  * @subpackage Annotation
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /** Internally used classes */
0024 // require_once 'Zend/Pdf/Element.php';
0025 // require_once 'Zend/Pdf/Element/Array.php';
0026 // require_once 'Zend/Pdf/Element/Dictionary.php';
0027 // require_once 'Zend/Pdf/Element/Name.php';
0028 // require_once 'Zend/Pdf/Element/Numeric.php';
0029 // require_once 'Zend/Pdf/Element/String.php';
0030 
0031 
0032 /** Zend_Pdf_Annotation */
0033 // require_once 'Zend/Pdf/Annotation.php';
0034 
0035 /**
0036  * A file attachment annotation contains a reference to a file,
0037  * which typically is embedded in the PDF file.
0038  *
0039  * @package    Zend_Pdf
0040  * @subpackage Annotation
0041  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0042  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0043  */
0044 class Zend_Pdf_Annotation_FileAttachment extends Zend_Pdf_Annotation
0045 {
0046     /**
0047      * Annotation object constructor
0048      *
0049      * @throws Zend_Pdf_Exception
0050      */
0051     public function __construct(Zend_Pdf_Element $annotationDictionary)
0052     {
0053         if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
0054             // require_once 'Zend/Pdf/Exception.php';
0055             throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
0056         }
0057 
0058         if ($annotationDictionary->Subtype === null  ||
0059             $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME  ||
0060             $annotationDictionary->Subtype->value != 'FileAttachment') {
0061             // require_once 'Zend/Pdf/Exception.php';
0062             throw new Zend_Pdf_Exception('Subtype => FileAttachment entry is requires');
0063         }
0064 
0065         parent::__construct($annotationDictionary);
0066     }
0067 
0068     /**
0069      * Create link annotation object
0070      *
0071      * @param float $x1
0072      * @param float $y1
0073      * @param float $x2
0074      * @param float $y2
0075      * @param string $fileSpecification
0076      * @return Zend_Pdf_Annotation_FileAttachment
0077      */
0078     public static function create($x1, $y1, $x2, $y2, $fileSpecification)
0079     {
0080         $annotationDictionary = new Zend_Pdf_Element_Dictionary();
0081 
0082         $annotationDictionary->Type    = new Zend_Pdf_Element_Name('Annot');
0083         $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('FileAttachment');
0084 
0085         $rectangle = new Zend_Pdf_Element_Array();
0086         $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
0087         $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
0088         $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
0089         $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
0090         $annotationDictionary->Rect = $rectangle;
0091 
0092         $fsDictionary = new Zend_Pdf_Element_Dictionary();
0093         $fsDictionary->Type = new Zend_Pdf_Element_Name('Filespec');
0094         $fsDictionary->F    = new Zend_Pdf_Element_String($fileSpecification);
0095 
0096         $annotationDictionary->FS = $fsDictionary;
0097 
0098 
0099         return new Zend_Pdf_Annotation_FileAttachment($annotationDictionary);
0100     }
0101 }