/** * Attach resource to the page * * @param string $type * @param \ZendPdf\Resource\AbstractResource $resource * @return string */ protected function _attachResource($type, Resource\AbstractResource $resource) { // Check that Resources dictionary contains appropriate resource set if ($this->_pageDictionary->Resources->{$type} === null) { $this->_pageDictionary->Resources->touch(); $this->_pageDictionary->Resources->{$type} = new InternalType\DictionaryObject(); } else { $this->_pageDictionary->Resources->{$type}->touch(); } // Check, that resource is already attached to resource set. $resObject = $resource->getResource(); foreach ($this->_pageDictionary->Resources->{$type}->getKeys() as $ResID) { if ($this->_pageDictionary->Resources->{$type}->{$ResID} === $resObject) { return $ResID; } } $idCounter = 1; do { $newResName = $type[0] . $idCounter++; } while ($this->_pageDictionary->Resources->{$type}->{$newResName} !== null); $this->_pageDictionary->Resources->{$type}->{$newResName} = $resObject; $this->_objFactory->attach($resource->getFactory()); return $newResName; }
/** * Prepare page to be rendered into PDF. * * @todo Don't forget to close all current graphics operations (like path drawing) * * @param \ZendPdf\ObjectFactory $objFactory * @throws \ZendPdf\Exception\ExceptionInterface */ public function render(ObjectFactory $objFactory) { $this->flush(); if ($objFactory === $this->_objFactory) { // Page is already attached to the document. return; } if ($this->_attached) { throw new Exception\LogicException('Page is attached to other document. Use clone $page to get it context free.'); } else { $objFactory->attach($this->_objFactory); } }