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.
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: Element.php 16978 2009-07-22 19:59:40Z alexander $
23 /** Zend_Pdf_Element_Object */
24 require_once 'Zend/Pdf/Element/Object.php';
28 * PDF file element implementation
31 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
32 * @license http://framework.zend.com/license/new-bsd New BSD License
34 abstract class Zend_Pdf_Element
37 const TYPE_NUMERIC
= 2;
38 const TYPE_STRING
= 3;
41 const TYPE_DICTIONARY
= 6;
42 const TYPE_STREAM
= 7;
46 * Reference to the top level indirect object, which contains this element.
48 * @var Zend_Pdf_Element_Object
50 private $_parentObject = null;
53 * Return type of the element.
54 * See ZPdfPDFConst for possible values
58 abstract public function getType();
61 * Convert element to a string, which can be directly
62 * written to a PDF file.
64 * $factory parameter defines operation context.
66 * @param Zend_Pdf_Factory $factory
69 abstract public function toString($factory = null);
73 * Set top level parent indirect object.
75 * @param Zend_Pdf_Element_Object $parent
77 public function setParentObject(Zend_Pdf_Element_Object
$parent)
79 $this->_parentObject
= $parent;
84 * Get top level parent indirect object.
86 * @return Zend_Pdf_Element_Object
88 public function getParentObject()
90 return $this->_parentObject
;
95 * Mark object as modified, to include it into new PDF file segment.
97 * We don't automate this action to keep control on PDF update process.
98 * All new objects are treated as "modified" automatically.
100 public function touch()
102 if ($this->_parentObject
!== null) {
103 $this->_parentObject
->touch();
108 * Clean up resources, used by object
110 public function cleanUp()
116 * Convert PDF element to PHP type.
120 public function toPhp()
126 * Convert PHP value into PDF element.
128 * @param mixed $input
129 * @return Zend_Pdf_Element
131 public static function phpToPdf($input)
133 if (is_numeric($input)) {
134 return new Zend_Pdf_Element_Numeric($input);
135 } else if (is_bool($input)) {
136 return new Zend_Pdf_Element_Boolean($input);
137 } else if (is_array($input)) {
138 $pdfElementsArray = array();
139 $isDictionary = false;
141 foreach ($input as $key => $value) {
142 if (is_string($key)) {
143 $isDictionary = true;
145 $pdfElementsArray[$key] = Zend_Pdf_Element
::phpToPdf($value);
149 return new Zend_Pdf_Element_Dictionary($pdfElementsArray);
151 return new Zend_Pdf_Element_Array($pdfElementsArray);
154 return new Zend_Pdf_Element_String((string)$input);