Trailer.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  18. * @license http://framework.zend.com/license/new-bsd New BSD License
  19. * @version $Id$
  20. */
  21. /** Zend_Pdf_Element_Dictionary */
  22. require_once 'Zend/Pdf/Element/Dictionary.php';
  23. /**
  24. * PDF file trailer
  25. *
  26. * @package Zend_Pdf
  27. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  28. * @license http://framework.zend.com/license/new-bsd New BSD License
  29. */
  30. abstract class Zend_Pdf_Trailer
  31. {
  32. private static $_allowedKeys = array('Size', 'Prev', 'Root', 'Encrypt', 'Info', 'ID', 'Index', 'W', 'XRefStm', 'DocChecksum');
  33. /**
  34. * Trailer dictionary.
  35. *
  36. * @var Zend_Pdf_Element_Dictionary
  37. */
  38. private $_dict;
  39. /**
  40. * Check if key is correct
  41. *
  42. * @param string $key
  43. * @throws Zend_Pdf_Exception
  44. */
  45. private function _checkDictKey($key)
  46. {
  47. if ( !in_array($key, self::$_allowedKeys) ) {
  48. /** @todo Make warning (log entry) instead of an exception */
  49. throw new Zend_Pdf_Exception("Unknown trailer dictionary key: '$key'.");
  50. }
  51. }
  52. /**
  53. * Object constructor
  54. *
  55. * @param Zend_Pdf_Element_Dictionary $dict
  56. */
  57. public function __construct(Zend_Pdf_Element_Dictionary $dict)
  58. {
  59. $this->_dict = $dict;
  60. foreach ($this->_dict->getKeys() as $dictKey) {
  61. $this->_checkDictKey($dictKey);
  62. }
  63. }
  64. /**
  65. * Get handler
  66. *
  67. * @param string $property
  68. * @return mixed
  69. */
  70. public function __get($property)
  71. {
  72. return $this->_dict->$property;
  73. }
  74. /**
  75. * Set handler
  76. *
  77. * @param string $property
  78. * @param mixed $value
  79. */
  80. public function __set($property, $value)
  81. {
  82. $this->_checkDictKey($property);
  83. $this->_dict->$property = $value;
  84. }
  85. /**
  86. * Return string trailer representation
  87. *
  88. * @return string
  89. */
  90. public function toString()
  91. {
  92. return "trailer\n" . $this->_dict->toString() . "\n";
  93. }
  94. /**
  95. * Get length of source PDF
  96. *
  97. * @return string
  98. */
  99. abstract public function getPDFLength();
  100. /**
  101. * Get PDF String
  102. *
  103. * @return string
  104. */
  105. abstract public function getPDFString();
  106. /**
  107. * Get header of free objects list
  108. * Returns object number of last free object
  109. *
  110. * @return integer
  111. */
  112. abstract public function getLastFreeObject();
  113. }