Esempio n. 1
0
 /**
  * Object constructor.
  *
  * If resource is not a \ZendPdf\InternalType\AbstractTypeObject object,
  * then stream object with specified value is generated.
  *
  * @param \ZendPdf\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);
     }
 }
Esempio n. 2
0
 /**
  * Dump current drawing instructions into the content stream.
  *
  * @todo Don't forget to close all current graphics operations (like path drawing)
  *
  * @throws \ZendPdf\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 = '';
 }