Keeper.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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_Trailer */
  22. require_once 'Zend/Pdf/Trailer.php';
  23. /** Zend_Pdf_Element_Reference_Context */
  24. require_once 'Zend/Pdf/Element/Reference/Context.php';
  25. /**
  26. * PDF file trailer.
  27. * Stores and provides access to the trailer parced from a PDF file
  28. *
  29. * @package Zend_Pdf
  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_Trailer_Keeper extends Zend_Pdf_Trailer
  34. {
  35. /**
  36. * Reference context
  37. *
  38. * @var Zend_Pdf_Element_Reference_Context
  39. */
  40. private $_context;
  41. /**
  42. * Previous trailer
  43. *
  44. * @var Zend_Pdf_Trailer
  45. */
  46. private $_prev;
  47. /**
  48. * Object constructor
  49. *
  50. * @param Zend_Pdf_Element_Dictionary $dict
  51. * @param Zend_Pdf_Element_Reference_Context $context
  52. * @param Zend_Pdf_Trailer $prev
  53. */
  54. public function __construct(Zend_Pdf_Element_Dictionary $dict,
  55. Zend_Pdf_Element_Reference_Context $context,
  56. $prev = null)
  57. {
  58. parent::__construct($dict);
  59. $this->_context = $context;
  60. $this->_prev = $prev;
  61. }
  62. /**
  63. * Setter for $this->_prev
  64. *
  65. * @param Zend_Pdf_Trailer_Keeper $prev
  66. */
  67. public function setPrev(Zend_Pdf_Trailer_Keeper $prev)
  68. {
  69. $this->_prev = $prev;
  70. }
  71. /**
  72. * Getter for $this->_prev
  73. *
  74. * @return Zend_Pdf_Trailer
  75. */
  76. public function getPrev()
  77. {
  78. return $this->_prev;
  79. }
  80. /**
  81. * Get length of source PDF
  82. *
  83. * @return string
  84. */
  85. public function getPDFLength()
  86. {
  87. return $this->_context->getParser()->getLength();
  88. }
  89. /**
  90. * Get PDF String
  91. *
  92. * @return string
  93. */
  94. public function getPDFString()
  95. {
  96. return $this->_context->getParser()->getString();
  97. }
  98. /**
  99. * Get reference table, which corresponds to the trailer.
  100. * Proxy to the $_context member methad call
  101. *
  102. * @return Zend_Pdf_Element_Reference_Context
  103. */
  104. public function getRefTable()
  105. {
  106. return $this->_context->getRefTable();
  107. }
  108. /**
  109. * Get header of free objects list
  110. * Returns object number of last free object
  111. *
  112. * @throws Zend_Pdf_Exception
  113. * @return integer
  114. */
  115. public function getLastFreeObject()
  116. {
  117. try {
  118. $this->_context->getRefTable()->getNextFree('0 65535 R');
  119. } catch (Zend_Pdf_Exception $e) {
  120. if ($e->getMessage() == 'Object not found.') {
  121. /**
  122. * Here is work around for some wrong generated PDFs.
  123. * We have not found reference to the header of free object list,
  124. * thus we treat it as there are no free objects.
  125. */
  126. return 0;
  127. }
  128. throw $e;
  129. }
  130. }
  131. }