Example #1
0
 /**
  * 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\ObjectFactory::createFactory(1);
     if ($resource instanceof InternalType\AbstractTypeObject) {
         $this->_resource = $this->_objectFactory->newObject($resource);
     } else {
         $this->_resource = $this->_objectFactory->newStreamObject($resource);
     }
 }
Example #2
0
 /**
  * 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();
 }
Example #3
0
 /**
  * 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);
 }
Example #4
0
File: Page.php Project: stunti/zf2
 /**
  * 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
  */
 public function flush()
 {
     if ($this->_saveCount != 0) {
         throw new Exception('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 = '';
 }