FileAttachment.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  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.
  14. *
  15. * @category Zend
  16. * @package Zend_Pdf
  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
  20. * @version $Id$
  21. */
  22. /** Zend_Pdf_Annotation */
  23. require_once 'Zend/Pdf/Annotation.php';
  24. /**
  25. * A file attachment annotation contains a reference to a file,
  26. * which typically is embedded in the PDF file.
  27. *
  28. * @package Zend_Pdf
  29. * @subpackage Annotation
  30. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  31. * @license http://framework.zend.com/license/new-bsd New BSD License
  32. */
  33. class Zend_Pdf_Annotation_FileAttachment extends Zend_Pdf_Annotation
  34. {
  35. /**
  36. * Annotation object constructor
  37. *
  38. * @throws Zend_Pdf_Exception
  39. */
  40. public function __construct(Zend_Pdf_Element $annotationDictionary)
  41. {
  42. if ($annotationDictionary->getType() != Zend_Pdf_Element::TYPE_DICTIONARY) {
  43. require_once 'Zend/Pdf/Exception.php';
  44. throw new Zend_Pdf_Exception('Annotation dictionary resource has to be a dictionary.');
  45. }
  46. if ($annotationDictionary->Subtype === null ||
  47. $annotationDictionary->Subtype->getType() != Zend_Pdf_Element::TYPE_NAME ||
  48. $annotationDictionary->Subtype->value != 'FileAttachment') {
  49. require_once 'Zend/Pdf/Exception.php';
  50. throw new Zend_Pdf_Exception('Subtype => FileAttachment entry is requires');
  51. }
  52. parent::__construct($annotationDictionary);
  53. }
  54. /**
  55. * Create link annotation object
  56. *
  57. * @param float $x1
  58. * @param float $y1
  59. * @param float $x2
  60. * @param float $y2
  61. * @param string $fileSpecification
  62. * @return Zend_Pdf_Annotation_FileAttachment
  63. */
  64. public static function create($x1, $y1, $x2, $y2, $fileSpecification)
  65. {
  66. $annotationDictionary = new Zend_Pdf_Element_Dictionary();
  67. $annotationDictionary->Type = new Zend_Pdf_Element_Name('Annot');
  68. $annotationDictionary->Subtype = new Zend_Pdf_Element_Name('FileAttachment');
  69. $rectangle = new Zend_Pdf_Element_Array();
  70. $rectangle->items[] = new Zend_Pdf_Element_Numeric($x1);
  71. $rectangle->items[] = new Zend_Pdf_Element_Numeric($y1);
  72. $rectangle->items[] = new Zend_Pdf_Element_Numeric($x2);
  73. $rectangle->items[] = new Zend_Pdf_Element_Numeric($y2);
  74. $annotationDictionary->Rect = $rectangle;
  75. $fsDictionary = new Zend_Pdf_Element_Dictionary();
  76. $fsDictionary->Type = new Zend_Pdf_Element_Name('Filespec');
  77. $fsDictionary->F = new Zend_Pdf_Element_String($fileSpecification);
  78. $annotationDictionary->FS = $fsDictionary;
  79. return new Zend_Pdf_Annotation_FileAttachment($annotationDictionary);
  80. }
  81. }