/** * Object constructor. * Constructor signatures: * * 1. Load PDF page from a parsed PDF file. * Object factory is created by PDF parser. * --------------------------------------------------------- * new Zend_Pdf_Page(Zend_Pdf_Element_Dictionary $pageDict, * Zend_Pdf_ElementFactory_Interface $factory); * --------------------------------------------------------- * * 2. Clone PDF page. * New page is created in the same context as source page. Object factory is shared. * Thus it will be attached to the document, but need to be placed into Zend_Pdf::$pages array * to be included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(Zend_Pdf_Page $page); * --------------------------------------------------------- * * 3. Create new page with a specified pagesize. * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(string $pagesize, Zend_Pdf_ElementFactory_Interface $factory = null); * --------------------------------------------------------- * * 4. Create new page with a specified pagesize (in default user space units). * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(numeric $width, numeric $height, Zend_Pdf_ElementFactory_Interface $factory = null); * --------------------------------------------------------- * * * @param mixed $param1 * @param mixed $param2 * @param mixed $param3 * @throws Zend_Pdf_Exception */ public function __construct($param1, $param2 = null, $param3 = null) { if ($param1 instanceof Zend_Pdf_Element_Reference && $param1->getType() == Zend_Pdf_Element::TYPE_DICTIONARY && $param2 instanceof Zend_Pdf_ElementFactory_Interface && $param3 === null) { $this->_pageDictionary = $param1; $this->_objFactory = $param2; $this->_attached = true; $this->_safeGS = false; return; } else { if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) { // Clone existing page. // Let already existing content and resources to be shared between pages // We don't give existing content modification functionality, so we don't need "deep copy" $this->_objFactory = $param1->_objFactory; $this->_attached =& $param1->_attached; $this->_safeGS = false; $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); foreach ($param1->_pageDictionary->getKeys() as $key) { if ($key == 'Contents') { // Clone Contents property $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array(); if ($param1->_pageDictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) { // Prepare array of content streams and add existing stream $this->_pageDictionary->Contents->items[] = $param1->_pageDictionary->Contents; } else { // Clone array of the content streams foreach ($param1->_pageDictionary->Contents->items as $srcContentStream) { $this->_pageDictionary->Contents->items[] = $srcContentStream; } } } else { $this->_pageDictionary->{$key} = $param1->_pageDictionary->{$key}; } } return; } else { if (is_string($param1) && ($param2 === null || $param2 instanceof Zend_Pdf_ElementFactory_Interface) && $param3 === null) { if ($param2 !== null) { $this->_objFactory = $param2; } else { //require_once 'Zend/Pdf/ElementFactory.php'; $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; /** New page created. That's users App responsibility to track GS changes */ switch (strtolower($param1)) { case 'a4': $param1 = Zend_Pdf_Page::SIZE_A4; break; case 'a4-landscape': $param1 = Zend_Pdf_Page::SIZE_A4_LANDSCAPE; break; case 'letter': $param1 = Zend_Pdf_Page::SIZE_LETTER; break; case 'letter-landscape': $param1 = Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE; break; default: // should be in "x:y" or "x:y:" form } $pageDim = explode(':', $param1); if (count($pageDim) == 2 || count($pageDim) == 3) { $pageWidth = $pageDim[0]; $pageHeight = $pageDim[1]; } else { /** * @todo support of user defined pagesize notations, like: * "210x297mm", "595x842", "8.5x11in", "612x792" */ //require_once 'Zend/Pdf/Exception.php'; throw new Zend_Pdf_Exception('Wrong pagesize notation.'); } /** * @todo support of pagesize recalculation to "default user space units" */ } else { if (is_numeric($param1) && is_numeric($param2) && ($param3 === null || $param3 instanceof Zend_Pdf_ElementFactory_Interface)) { if ($param3 !== null) { $this->_objFactory = $param3; } else { //require_once 'Zend/Pdf/ElementFactory.php'; $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; /** New page created. That's users App responsibility to track GS changes */ $pageWidth = $param1; $pageHeight = $param2; } else { //require_once 'Zend/Pdf/Exception.php'; throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.'); } } } } $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); $this->_pageDictionary->Type = new Zend_Pdf_Element_Name('Page'); //require_once 'Zend/Pdf.php'; $this->_pageDictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate()); $this->_pageDictionary->Resources = new Zend_Pdf_Element_Dictionary(); $this->_pageDictionary->MediaBox = new Zend_Pdf_Element_Array(); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight); $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array(); }
public function __construct($source = null, $revision = null, $load = false) { parent::__construct($source, $revision, $load); $this->_currentTime = Zend_Pdf::pdfDate(); }
/** * Object constructor. * Constructor signatures: * * 1. Load PDF page from a parsed PDF file. * Object factory is created by PDF parser. * --------------------------------------------------------- * new Zend_Pdf_Page(Zend_Pdf_Element_Dictionary $pageDict, * Zend_Pdf_ElementFactory_Interface $factory); * --------------------------------------------------------- * * 2. Clone PDF page. * New page is created in the same context as source page. Object factory is shared. * Thus it will be attached to the document, but need to be placed into Zend_Pdf::$pages array * to be included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(Zend_Pdf_Page $page); * --------------------------------------------------------- * * 3. Create new page with a specified pagesize. * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(string $pagesize, Zend_Pdf_ElementFactory_Interface $factory = null); * --------------------------------------------------------- * * 4. Create new page with a specified pagesize (in default user space units). * If $factory is null then it will be created and page must be attached to the document to be * included into output. * --------------------------------------------------------- * new Zend_Pdf_Page(numeric $width, numeric $height, Zend_Pdf_ElementFactory_Interface $factory = null); * --------------------------------------------------------- * * * @param mixed $param1 * @param mixed $param2 * @param mixed $param3 * @throws Zend_Pdf_Exception */ public function __construct($param1, $param2 = null, $param3 = null) { if ($param1 instanceof Zend_Pdf_Element_Reference && $param1->getType() == Zend_Pdf_Element::TYPE_DICTIONARY && $param2 instanceof Zend_Pdf_ElementFactory_Interface && $param3 === null) { $this->_pageDictionary = $param1; $this->_objFactory = $param2; $this->_attached = true; return; } else { if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) { /** @todo implementation */ throw new Zend_Pdf_Exception('Not implemented yet.'); } else { if (is_string($param1) && ($param2 === null || $param2 instanceof Zend_Pdf_ElementFactory_Interface) && $param3 === null) { $this->_objFactory = $param2 !== null ? $param2 : Zend_Pdf_ElementFactory::createFactory(1); $this->_attached = false; switch (strtolower($param1)) { case 'a4': $param1 = Zend_Pdf_Page::SIZE_A4; break; case 'a4-landscape': $param1 = Zend_Pdf_Page::SIZE_A4_LANDSCAPE; break; case 'letter': $param1 = Zend_Pdf_Page::SIZE_LETTER; break; case 'letter-landscape': $param1 = Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE; break; default: // should be in "x:y" form } $pageDim = explode(':', $param1); if (count($pageDim) == 3) { $pageWidth = $pageDim[0]; $pageHeight = $pageDim[1]; } else { /** * @todo support of user defined pagesize notations, like: * "210x297mm", "595x842", "8.5x11in", "612x792" */ throw new Zend_Pdf_Exception('Wrong pagesize notation.'); } /** * @todo support of pagesize recalculation to "default user space units" */ } else { if (is_numeric($param1) && is_numeric($param2) && ($param3 === null || $param3 instanceof Zend_Pdf_ElementFactory_Interface)) { $this->_objFactory = $param3 !== null ? $param3 : Zend_Pdf_ElementFactory::createFactory(1); $this->_attached = false; $pageWidth = $param1; $pageHeight = $param2; } else { throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.'); } } } } $this->_pageDictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); $this->_pageDictionary->Type = new Zend_Pdf_Element_Name('Page'); $this->_pageDictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate()); $this->_pageDictionary->Resources = new Zend_Pdf_Element_Dictionary(); $this->_pageDictionary->MediaBox = new Zend_Pdf_Element_Array(); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth); $this->_pageDictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight); $this->_pageDictionary->Contents = new Zend_Pdf_Element_Array(); }
public function __construct($param1, $param2 = null, $param3 = null) { if (($param1 instanceof Zend_Pdf_Element_Reference || $param1 instanceof Zend_Pdf_Element_Object) && $param2 instanceof Zend_Pdf_ElementFactory_Interface && $param3 === null) { switch ($param1->getType()) { case Zend_Pdf_Element::TYPE_DICTIONARY: $this->_dictionary = $param1; $this->_objFactory = $param2; $this->_attached = true; $this->_safeGS = false; return; break; case Zend_Pdf_Element::TYPE_NULL: $this->_objFactory = $param2; $pageWidth = $pageHeight = 0; break; default: throw new Zend_Pdf_Exception('Unrecognized object type.'); break; } } else { if ($param1 instanceof Zend_Pdf_Page && $param2 === null && $param3 === null) { $this->_objFactory = $param1->_objFactory; $this->_attached =& $param1->_attached; $this->_safeGS = false; $this->_dictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); foreach ($param1->_dictionary->getKeys() as $key) { if ($key == 'Contents') { $this->_dictionary->Contents = new Zend_Pdf_Element_Array(); if ($param1->_dictionary->Contents->getType() != Zend_Pdf_Element::TYPE_ARRAY) { $this->_dictionary->Contents->items[] = $param1->_dictionary->Contents; } else { foreach ($param1->_dictionary->Contents->items as $srcContentStream) { $this->_dictionary->Contents->items[] = $srcContentStream; } } } else { $this->_dictionary->{$key} = $param1->_dictionary->{$key}; } } return; } else { if (is_string($param1) && ($param2 === null || $param2 instanceof Zend_Pdf_ElementFactory_Interface) && $param3 === null) { if ($param2 !== null) { $this->_objFactory = $param2; } else { $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; switch (strtolower($param1)) { case 'a4': $param1 = Zend_Pdf_Page::SIZE_A4; break; case 'a4-landscape': $param1 = Zend_Pdf_Page::SIZE_A4_LANDSCAPE; break; case 'letter': $param1 = Zend_Pdf_Page::SIZE_LETTER; break; case 'letter-landscape': $param1 = Zend_Pdf_Page::SIZE_LETTER_LANDSCAPE; break; default: } $pageDim = explode(':', $param1); if (count($pageDim) == 2 || count($pageDim) == 3) { $pageWidth = $pageDim[0]; $pageHeight = $pageDim[1]; } else { throw new Zend_Pdf_Exception('Wrong pagesize notation.'); } } else { if (is_numeric($param1) && is_numeric($param2) && ($param3 === null || $param3 instanceof Zend_Pdf_ElementFactory_Interface)) { if ($param3 !== null) { $this->_objFactory = $param3; } else { $this->_objFactory = Zend_Pdf_ElementFactory::createFactory(1); } $this->_attached = false; $this->_safeGS = true; $pageWidth = $param1; $pageHeight = $param2; } else { throw new Zend_Pdf_Exception('Unrecognized method signature, wrong number of arguments or wrong argument types.'); } } } } $this->_dictionary = $this->_objFactory->newObject(new Zend_Pdf_Element_Dictionary()); $this->_dictionary->Type = new Zend_Pdf_Element_Name('Page'); $this->_dictionary->LastModified = new Zend_Pdf_Element_String(Zend_Pdf::pdfDate()); $this->_dictionary->Resources = new Zend_Pdf_Element_Dictionary(); $this->_dictionary->MediaBox = new Zend_Pdf_Element_Array(); $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric(0); $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageWidth); $this->_dictionary->MediaBox->items[] = new Zend_Pdf_Element_Numeric($pageHeight); $this->_dictionary->Contents = new Zend_Pdf_Element_Array(); }