File indexing completed on 2024-12-22 05:36:56
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 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 0023 /** Zend_Pdf_Trailer */ 0024 // require_once 'Zend/Pdf/Trailer.php'; 0025 0026 /** 0027 * PDF file trailer. 0028 * Stores and provides access to the trailer parced from a PDF file 0029 * 0030 * @package Zend_Pdf 0031 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0032 * @license http://framework.zend.com/license/new-bsd New BSD License 0033 */ 0034 class Zend_Pdf_Trailer_Keeper extends Zend_Pdf_Trailer 0035 { 0036 /** 0037 * Reference context 0038 * 0039 * @var Zend_Pdf_Element_Reference_Context 0040 */ 0041 private $_context; 0042 0043 /** 0044 * Previous trailer 0045 * 0046 * @var Zend_Pdf_Trailer 0047 */ 0048 private $_prev; 0049 0050 0051 /** 0052 * Object constructor 0053 * 0054 * @param Zend_Pdf_Element_Dictionary $dict 0055 * @param Zend_Pdf_Element_Reference_Context $context 0056 * @param Zend_Pdf_Trailer $prev 0057 */ 0058 public function __construct(Zend_Pdf_Element_Dictionary $dict, 0059 Zend_Pdf_Element_Reference_Context $context, 0060 Zend_Pdf_Trailer $prev = null) 0061 { 0062 parent::__construct($dict); 0063 0064 $this->_context = $context; 0065 $this->_prev = $prev; 0066 } 0067 0068 /** 0069 * Setter for $this->_prev 0070 * 0071 * @param Zend_Pdf_Trailer_Keeper $prev 0072 */ 0073 public function setPrev(Zend_Pdf_Trailer_Keeper $prev) 0074 { 0075 $this->_prev = $prev; 0076 } 0077 0078 /** 0079 * Getter for $this->_prev 0080 * 0081 * @return Zend_Pdf_Trailer 0082 */ 0083 public function getPrev() 0084 { 0085 return $this->_prev; 0086 } 0087 0088 /** 0089 * Get length of source PDF 0090 * 0091 * @return string 0092 */ 0093 public function getPDFLength() 0094 { 0095 return $this->_context->getParser()->getLength(); 0096 } 0097 0098 /** 0099 * Get PDF String 0100 * 0101 * @return string 0102 */ 0103 public function getPDFString() 0104 { 0105 return $this->_context->getParser()->getString(); 0106 } 0107 0108 /** 0109 * Get reference table, which corresponds to the trailer. 0110 * Proxy to the $_context member methad call 0111 * 0112 * @return Zend_Pdf_Element_Reference_Context 0113 */ 0114 public function getRefTable() 0115 { 0116 return $this->_context->getRefTable(); 0117 } 0118 0119 /** 0120 * Get header of free objects list 0121 * Returns object number of last free object 0122 * 0123 * @throws Zend_Pdf_Exception 0124 * @return integer 0125 */ 0126 public function getLastFreeObject() 0127 { 0128 try { 0129 $this->_context->getRefTable()->getNextFree('0 65535 R'); 0130 } catch (Zend_Pdf_Exception $e) { 0131 if ($e->getMessage() == 'Object not found.') { 0132 /** 0133 * Here is work around for some wrong generated PDFs. 0134 * We have not found reference to the header of free object list, 0135 * thus we treat it as there are no free objects. 0136 */ 0137 return 0; 0138 } 0139 0140 throw new Zend_Pdf_Exception($e->getMessage(), $e->getCode(), $e); 0141 } 0142 } 0143 }