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