Exemple #1
0
 /**
  * Dump Action and its child actions into PDF structures
  *
  * Returns dictionary indirect object or reference
  *
  * @internal
  * @param \Zend\PDF\ObjectFactory\ObjectFactory $factory   Object factory for newly created indirect objects
  * @param SplObjectStorage $processedActions  list of already processed actions
  *                                            (used to prevent infinity loop caused by cyclic references)
  * @return \Zend\PDF\InternalType\IndirectObject|\Zend\PDF\InternalType\IndirectObjectReference
  */
 public function dumpAction(PDF\ObjectFactory\ObjectFactoryInterface $factory, \SplObjectStorage $processedActions = null)
 {
     if ($processedActions === null) {
         $processedActions = new \SplObjectStorage();
     }
     if ($processedActions->contains($this)) {
         throw new PDF\Exception('Action chain cyclyc reference is detected.');
     }
     $processedActions->attach($this);
     $childListUpdated = false;
     if (count($this->_originalNextList) != count($this->next)) {
         // If original and current children arrays have different size then children list was updated
         $childListUpdated = true;
     } else {
         if (!(array_keys($this->_originalNextList) === array_keys($this->next))) {
             // If original and current children arrays have different keys (with a glance to an order) then children list was updated
             $childListUpdated = true;
         } else {
             foreach ($this->next as $key => $childAction) {
                 if ($this->_originalNextList[$key] !== $childAction) {
                     $childListUpdated = true;
                     break;
                 }
             }
         }
     }
     if ($childListUpdated) {
         $this->_actionDictionary->touch();
         switch (count($this->next)) {
             case 0:
                 $this->_actionDictionary->Next = null;
                 break;
             case 1:
                 $child = reset($this->next);
                 $this->_actionDictionary->Next = $child->dumpAction($factory, $processedActions);
                 break;
             default:
                 $pdfChildArray = new InternalType\ArrayObject();
                 foreach ($this->next as $child) {
                     $pdfChildArray->items[] = $child->dumpAction($factory, $processedActions);
                 }
                 $this->_actionDictionary->Next = $pdfChildArray;
                 break;
         }
     } else {
         foreach ($this->next as $child) {
             $child->dumpAction($factory, $processedActions);
         }
     }
     if ($this->_actionDictionary instanceof InternalType\DictionaryObject) {
         // It's a newly created action. Register it within object factory and return indirect object
         return $factory->newObject($this->_actionDictionary);
     } else {
         // It's a loaded object
         return $this->_actionDictionary;
     }
 }
    /**
     * Set text to be displayed for the annotation or, if this type of annotation
     * does not display text, an alternate description of the annotation’s contents
     * in human-readable form.
     *
     * @param string $text
     * @return \Zend\Pdf\Annotation\AbstractAnnotation
     */
    public function setText($text) {
        if ($this->_annotationDictionary->Contents === null) {
            $this->_annotationDictionary->touch();
            $this->_annotationDictionary->Contents = new InternalType\StringObject($text);
        } else {
            $this->_annotationDictionary->Contents->touch();
            $this->_annotationDictionary->Contents->value = new InternalType\StringObject($text);
        }

        return $this;
    }
Exemple #3
0
 /**
  *
  * @param \Zend\Pdf\Annotation\AbstractAnnotation $annotation
  * @return \Zend\Pdf\Page
  */
 public function attachAnnotation(Annotation\AbstractAnnotation $annotation)
 {
     $annotationDictionary = $annotation->getResource();
     if (!$annotationDictionary instanceof InternalType\IndirectObject && !$annotationDictionary instanceof InternalType\IndirectObjectReference) {
         $annotationDictionary = $this->_objFactory->newObject($annotationDictionary);
     }
     if ($this->_pageDictionary->Annots === null) {
         $this->_pageDictionary->touch();
         $this->_pageDictionary->Annots = new InternalType\ArrayObject();
     } else {
         $this->_pageDictionary->Annots->touch();
     }
     $this->_pageDictionary->Annots->items[] = $annotationDictionary;
     $annotationDictionary->touch();
     $annotationDictionary->P = $this->_pageDictionary;
     return $this;
 }
Exemple #4
0
 /**
  * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
  *
  * @param \Zend\Pdf\ObjectFactory $factory  The factory to attach
  * @param array &$processed  List of already processed indirect objects, used to avoid objects duplication
  * @param integer $mode  Cloning mode (defines filter for objects cloning)
  * @returns \Zend\Pdf\InternalType\AbstractTypeObject
  */
 public function makeClone(ObjectFactory $factory, array &$processed, $mode)
 {
     $id = spl_object_hash($this);
     if (isset($processed[$id])) {
         // Do nothing if object is already processed
         // return it
         return $processed[$id];
     }
     $streamValue = $this->_value;
     $streamDictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
     // Make new empty instance of stream object and register it in $processed container
     $processed[$id] = $clonedObject = $factory->newStreamObject('');
     // Copy current object data and state
     $clonedObject->_dictionary = $this->_dictionary->makeClone($factory, $processed, $mode);
     $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
     $clonedObject->_initialDictionaryData = $this->_initialDictionaryData;
     $clonedObject->_streamDecoded = $this->_streamDecoded;
     return $clonedObject;
 }
 public function testAdd()
 {
     $dictionaryObj = new InternalType\DictionaryObject();
     $dictionaryObj->add(new InternalType\NameObject('Var1'), new InternalType\BooleanObject(false));
     $dictionaryObj->add(new InternalType\NameObject('Var2'), new InternalType\NumericObject(100.426));
     $dictionaryObj->add(new InternalType\NameObject('Var3'), new InternalType\NameObject('MyName'));
     $dictionaryObj->add(new InternalType\NameObject('Var4'), new InternalType\StringObject('some text'));
     $this->assertEquals($dictionaryObj->toString(),
                         '<</Var1 false /Var2 100.426 /Var3 /MyName /Var4 (some text) >>');
 }
Exemple #6
0
 /**
  * Return string trailer representation
  *
  * @return string
  */
 public function toString()
 {
     return "trailer\n" . $this->_dict->toString() . "\n";
 }
Exemple #7
0
 /**
  * Read dictionary PDF object
  * Also reads trailing '>>' from a pdf stream
  *
  * @return \Zend\Pdf\InternalType\DictionaryObject
  * @throws \Zend\Pdf\Exception
  */
 private function _readDictionary()
 {
     $dictionary = new InternalType\DictionaryObject();
     while (strlen($nextLexeme = $this->readLexeme()) != 0) {
         if ($nextLexeme != '>>') {
             $nameStart = $this->offset - strlen($nextLexeme);
             $name = $this->readElement($nextLexeme);
             $value = $this->readElement();
             if (!$name instanceof InternalType\NameObject) {
                 throw new Pdf\Exception(sprintf('PDF file syntax error. Name object expected while dictionary reading. Offset - 0x%X.', $nameStart));
             }
             $dictionary->add($name, $value);
         } else {
             return $dictionary;
         }
     }
     throw new Pdf\Exception(sprintf('PDF file syntax error. Unexpected end of file while dictionary reading. Offset - 0x%X. \'>>\' expected.', $this->offset));
 }
Exemple #8
0
 /**
  * Dump Outline and its child outlines into PDF structures
  *
  * Returns dictionary indirect object or reference
  *
  * @internal
  * @param \Zend\Pdf\ObjectFactory    $factory object factory for newly created indirect objects
  * @param boolean $updateNavigation  Update navigation flag
  * @param \Zend\Pdf\InternalType\AbstractTypeObject $parent   Parent outline dictionary reference
  * @param \Zend\Pdf\InternalType\AbstractTypeObject $prev     Previous outline dictionary reference
  * @param SplObjectStorage $processedOutlines  List of already processed outlines
  * @return \Zend\Pdf\InternalType\AbstractTypeObject
  * @throws \Zend\Pdf\Exception
  */
 public function dumpOutline(ObjectFactory $factory, $updateNavigation, InternalType\AbstractTypeObject $parent, InternalType\AbstractTypeObject $prev = null, \SplObjectStorage $processedOutlines = null)
 {
     if ($processedOutlines === null) {
         $processedOutlines = new \SplObjectStorage();
     }
     $processedOutlines->attach($this);
     if ($updateNavigation) {
         $this->_outlineDictionary->touch();
         $this->_outlineDictionary->Parent = $parent;
         $this->_outlineDictionary->Prev = $prev;
         $this->_outlineDictionary->Next = null;
     }
     $updateChildNavigation = false;
     if (count($this->_originalChildOutlines) != count($this->childOutlines)) {
         // If original and current children arrays have different size then children list was updated
         $updateChildNavigation = true;
     } else {
         if (!(array_keys($this->_originalChildOutlines) === array_keys($this->childOutlines))) {
             // If original and current children arrays have different keys (with a glance to an order) then children list was updated
             $updateChildNavigation = true;
         } else {
             foreach ($this->childOutlines as $key => $childOutline) {
                 if ($this->_originalChildOutlines[$key] !== $childOutline) {
                     $updateChildNavigation = true;
                     break;
                 }
             }
         }
     }
     $lastChild = null;
     if ($updateChildNavigation) {
         $this->_outlineDictionary->touch();
         $this->_outlineDictionary->First = null;
         foreach ($this->childOutlines as $childOutline) {
             if ($processedOutlines->contains($childOutline)) {
                 throw new Exception\CorruptedPdfException('Outlines cyclyc reference is detected.');
             }
             if ($lastChild === null) {
                 // First pass. Update Outlines dictionary First entry using corresponding value
                 $lastChild = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, null, $processedOutlines);
                 $this->_outlineDictionary->First = $lastChild;
             } else {
                 // Update previous outline dictionary Next entry (Prev is updated within dumpOutline() method)
                 $childOutlineDictionary = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, $lastChild, $processedOutlines);
                 $lastChild->Next = $childOutlineDictionary;
                 $lastChild = $childOutlineDictionary;
             }
         }
         $this->_outlineDictionary->Last = $lastChild;
         if (count($this->childOutlines) != 0) {
             $this->_outlineDictionary->Count = new InternalType\NumericObject(($this->isOpen() ? 1 : -1) * count($this->childOutlines));
         } else {
             $this->_outlineDictionary->Count = null;
         }
     } else {
         foreach ($this->childOutlines as $childOutline) {
             if ($processedOutlines->contains($childOutline)) {
                 throw new Exception\CorruptedPdfException('Outlines cyclyc reference is detected.');
             }
             $lastChild = $childOutline->dumpOutline($factory, $updateChildNavigation, $this->_outlineDictionary, $lastChild, $processedOutlines);
         }
     }
     return $this->_outlineDictionary;
 }