/** * Attach resource to the page * * @param string $type * @param Zend_Pdf_Resource $resource * @return string */ protected function _attachResource($type, Zend_Pdf_Resource $resource) { // Check that Resources dictionary contains appropriate resource set if ($this->_pageDictionary->Resources->{$type} === null) { $this->_pageDictionary->Resources->touch(); $this->_pageDictionary->Resources->{$type} = new Zend_Pdf_Element_Dictionary(); } 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; }
/** * Attach resource to the canvas * * Method returns a name of the resource which can be used * as a resource reference within drawing instructions stream * Allowed types: 'ExtGState', 'ColorSpace', 'Pattern', 'Shading', * 'XObject', 'Font', 'Properties' * * @param string $type * @param Zend_Pdf_Resource $resource * @return string */ protected function _attachResource($type, Zend_Pdf_Resource $resource) { // Check, that resource is already attached to resource set. $resObject = $resource->getResource(); foreach ($this->_resources[$type] as $resName => $collectedResObject) { if ($collectedResObject === $resObject) { return $resName; } } $idCounter = 1; do { $newResName = $type[0] . $idCounter++; } while (isset($this->_resources[$type][$newResName])); $this->_resources[$type][$newResName] = $resObject; return $newResName; }