/** * Object constructor. * * If resource is not a \Zend\Pdf\InternalType\AbstractTypeObject object, * then stream object with specified value is generated. * * @param \Zend\Pdf\InternalType\AbstractTypeObject|string $resource */ public function __construct($resource) { $this->_objectFactory = ObjectFactory::createFactory(1); if ($resource instanceof InternalType\AbstractTypeObject) { $this->_resource = $this->_objectFactory->newObject($resource); } else { $this->_resource = $this->_objectFactory->newStreamObject($resource); } }
/** * Dump current drawing instructions into the content stream. * * @todo Don't forget to close all current graphics operations (like path drawing) * * @throws \Zend\Pdf\Exception\ExceptionInterface */ public function flush() { if ($this->_saveCount != 0) { throw new Exception\LogicException('Saved graphics state is not restored'); } if ($this->_contents == '') { return; } if ($this->_pageDictionary->Contents->getType() != InternalType\AbstractTypeObject::TYPE_ARRAY) { /** * It's a stream object. * Prepare Contents page attribute for update. */ $this->_pageDictionary->touch(); $currentPageContents = $this->_pageDictionary->Contents; $this->_pageDictionary->Contents = new InternalType\ArrayObject(); $this->_pageDictionary->Contents->items[] = $currentPageContents; } else { $this->_pageDictionary->Contents->touch(); } if (!$this->_safeGS && count($this->_pageDictionary->Contents->items) != 0) { /** * Page already has some content which is not treated as safe. * * Add save/restore GS operators */ $this->_addProcSet('PDF'); $newContentsArray = new InternalType\ArrayObject(); $newContentsArray->items[] = $this->_objFactory->newStreamObject(" q\n"); foreach ($this->_pageDictionary->Contents->items as $contentStream) { $newContentsArray->items[] = $contentStream; } $newContentsArray->items[] = $this->_objFactory->newStreamObject(" Q\n"); $this->_pageDictionary->touch(); $this->_pageDictionary->Contents = $newContentsArray; $this->_safeGS = true; } $this->_pageDictionary->Contents->items[] = $this->_objFactory->newStreamObject($this->_contents); $this->_contents = ''; }
/** * Sets the document-level Metadata (mast be valid XMP document) * * @param string $metadata */ public function setMetadata($metadata) { $metadataObject = $this->_objFactory->newStreamObject($metadata); $metadataObject->dictionary->Type = new InternalType\NameObject('Metadata'); $metadataObject->dictionary->Subtype = new InternalType\NameObject('XML'); $this->_trailer->Root->Metadata = $metadataObject; $this->_trailer->Root->touch(); }
/** * Generate new \Zend\Pdf\InternalType\StreamObject * * @todo Reusage of the freed object. It's not a support of new feature, but only improvement. * * @param mixed $objectValue * @return \Zend\Pdf\InternalType\StreamObject */ public function newStreamObject($streamValue) { return $this->_factory->newStreamObject($streamValue); }