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
 /**
  *
  * @param \ZendPdf\Annotation\AbstractAnnotation $annotation
  * @return \ZendPdf\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;
 }
Esempio n. 3
0
 /**
  * Detach PDF object from the factory (if applicable), clone it and attach to new factory.
  *
  * @param \ZendPdf\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 \ZendPdf\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];
     }
     // Create obect with null value and register it in $processed container
     $processed[$id] = $clonedObject = $factory->newObject(new NullObject());
     // Pecursively process actual data
     $clonedObject->_value = $this->_value->makeClone($factory, $processed, $mode);
     if ($clonedObject->_value instanceof NullObject) {
         // Do not store null objects within $processed container since it may be filtered
         // by $mode parameter but used in some future pass
         unset($processed[$id]);
         // Return direct null object
         return $clonedObject->_value;
     }
     return $clonedObject;
 }
Esempio n. 4
0
 /**
  * Dump Outline and its child outlines into PDF structures
  *
  * Returns dictionary indirect object or reference
  *
  * @internal
  * @param \ZendPdf\ObjectFactory    $factory object factory for newly created indirect objects
  * @param boolean $updateNavigation  Update navigation flag
  * @param \ZendPdf\InternalType\AbstractTypeObject $parent   Parent outline dictionary reference
  * @param \ZendPdf\InternalType\AbstractTypeObject $prev     Previous outline dictionary reference
  * @param SplObjectStorage $processedOutlines  List of already processed outlines
  * @return \ZendPdf\InternalType\AbstractTypeObject
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 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);
     $outlineDictionary = $factory->newObject(new InternalType\DictionaryObject());
     $outlineDictionary->Title = new InternalType\StringObject($this->getTitle());
     $target = $this->getTarget();
     if ($target === null) {
         // Do nothing
     } elseif ($target instanceof Pdf\Destination\AbstractDestination) {
         $outlineDictionary->Dest = $target->getResource();
     } elseif ($target instanceof Action\AbstractAction) {
         $outlineDictionary->A = $target->getResource();
     } else {
         throw new Exception\CorruptedPdfException('Outline target has to be \\ZendPdf\\Destination, \\ZendPdf\\Action object or null');
     }
     $color = $this->getColor();
     if ($color !== null) {
         $components = $color->getComponents();
         $colorComponentElements = array(new InternalType\NumericObject($components[0]), new InternalType\NumericObject($components[1]), new InternalType\NumericObject($components[2]));
         $outlineDictionary->C = new InternalType\ArrayObject($colorComponentElements);
     }
     if ($this->isItalic() || $this->isBold()) {
         $outlineDictionary->F = new InternalType\NumericObject(($this->isItalic() ? 1 : 0) | ($this->isBold() ? 2 : 0));
         // Bit 2 - Bold
     }
     $outlineDictionary->Parent = $parent;
     $outlineDictionary->Prev = $prev;
     $lastChild = null;
     foreach ($this->childOutlines as $childOutline) {
         if ($processedOutlines->contains($childOutline)) {
             throw new Exception\CorruptedPdfException('Outlines cyclyc reference is detected.');
         }
         if ($lastChild === null) {
             $lastChild = $childOutline->dumpOutline($factory, true, $outlineDictionary, null, $processedOutlines);
             $outlineDictionary->First = $lastChild;
         } else {
             $childOutlineDictionary = $childOutline->dumpOutline($factory, true, $outlineDictionary, $lastChild, $processedOutlines);
             $lastChild->Next = $childOutlineDictionary;
             $lastChild = $childOutlineDictionary;
         }
     }
     $outlineDictionary->Last = $lastChild;
     if (count($this->childOutlines) != 0) {
         $outlineDictionary->Count = new InternalType\NumericObject(($this->isOpen() ? 1 : -1) * count($this->childOutlines));
     }
     return $outlineDictionary;
 }