You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
3.5 KiB

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