/** * Named destination object constructor * * @param $resource * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $resource) { if ($resource->getType() != InternalType\AbstractTypeObject::TYPE_NAME && $resource->getType() != InternalType\AbstractTypeObject::TYPE_STRING) { throw new Exception\CorruptedPdfException('Named destination resource must be a PDF name or a PDF string.'); } $this->_nameElement = $resource; }
/** * AbstractExplicitDestination destination object constructor * * @param \ZendPdf\InternalType\AbstractTypeObject $destinationArray * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $destinationArray) { if ($destinationArray->getType() != InternalType\AbstractTypeObject::TYPE_ARRAY) { throw new Exception\CorruptedPdfException('Explicit destination resource Array must be a direct or an indirect array object.'); } $this->_destinationArray = $destinationArray; switch (count($this->_destinationArray->items)) { case 0: throw new Exception\CorruptedPdfException('Destination array must contain a page reference.'); break; case 1: throw new Exception\CorruptedPdfException('Destination array must contain a destination type name.'); break; default: // Do nothing break; } switch ($this->_destinationArray->items[0]->getType()) { case InternalType\AbstractTypeObject::TYPE_NUMERIC: $this->_isRemote = true; break; case InternalType\AbstractTypeObject::TYPE_DICTIONARY: $this->_isRemote = false; break; default: throw new Exception\CorruptedPdfException('Destination target must be a page number or page dictionary object.'); break; } }
/** * Object constructor * * @param $rootDictionary root of name dictionary * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $rootDictionary) { if ($rootDictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('Name tree root must be a dictionary.'); } $intermediateNodes = array(); $leafNodes = array(); if ($rootDictionary->Kids !== null) { $intermediateNodes[] = $rootDictionary; } else { $leafNodes[] = $rootDictionary; } while (count($intermediateNodes) != 0) { $newIntermediateNodes = array(); foreach ($intermediateNodes as $node) { foreach ($node->Kids->items as $childNode) { if ($childNode->Kids !== null) { $newIntermediateNodes[] = $childNode; } else { $leafNodes[] = $childNode; } } } $intermediateNodes = $newIntermediateNodes; } foreach ($leafNodes as $leafNode) { $destinationsCount = count($leafNode->Names->items) / 2; for ($count = 0; $count < $destinationsCount; $count++) { $this->_items[$leafNode->Names->items[$count * 2]->value] = $leafNode->Names->items[$count * 2 + 1]; } } }
/** * Annotation object constructor * * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $annotationDictionary) { if ($annotationDictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('Annotation dictionary resource has to be a dictionary.'); } if ($annotationDictionary->Subtype === null || $annotationDictionary->Subtype->getType() != InternalType\AbstractTypeObject::TYPE_NAME || $annotationDictionary->Subtype->value != 'Text') { throw new Exception\CorruptedPdfException('Subtype => Text entry is requires'); } parent::__construct($annotationDictionary); }
/** * Annotation object constructor * * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $annotationDictionary) { if ($annotationDictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('Annotation dictionary resource has to be a dictionary.'); } if ($annotationDictionary->Subtype === null || $annotationDictionary->Subtype->getType() != InternalType\AbstractTypeObject::TYPE_NAME || !in_array($annotationDictionary->Subtype->value, array(self::SUBTYPE_HIGHLIGHT, self::SUBTYPE_UNDERLINE, self::SUBTYPE_SQUIGGLY, self::SUBTYPE_STRIKEOUT))) { throw new Exception\CorruptedPdfException('Subtype => Markup entry is omitted or has wrong value.'); } parent::__construct($annotationDictionary); }
/** * Load Destination object from a specified resource * * @internal * @param $destinationArray * @return \ZendPdf\Destination\AbstractDestination */ public static function load(InternalType\AbstractTypeObject $resource) { if ($resource->getType() == InternalType\AbstractTypeObject::TYPE_NAME || $resource->getType() == InternalType\AbstractTypeObject::TYPE_STRING) { return new Named($resource); } if ($resource->getType() != InternalType\AbstractTypeObject::TYPE_ARRAY) { throw new Exception\CorruptedPdfException('An explicit destination must be a direct or an indirect array object.'); } if (count($resource->items) < 2) { throw new Exception\CorruptedPdfException('An explicit destination array must contain at least two elements.'); } switch ($resource->items[1]->value) { case 'XYZ': return new Zoom($resource); break; case 'Fit': return new Fit($resource); break; case 'FitH': return new FitHorizontally($resource); break; case 'FitV': return new FitVertically($resource); break; case 'FitR': return new FitRectangle($resource); break; case 'FitB': return new FitBoundingBox($resource); break; case 'FitBH': return new FitBoundingBoxHorizontally($resource); break; case 'FitBV': return new FitBoundingBoxVertically($resource); break; default: return new Unknown($resource); break; } }
/** * Parse resource and return it as an Action or Explicit Destination * * $param \ZendPdf\InternalType $resource * @return \ZendPdf\Destination\AbstractDestination|\ZendPdf\Action\AbstractAction * @throws \ZendPdf\Exception\ExceptionInterface */ public static function load(InternalType\AbstractTypeObject $resource) { if ($resource->getType() == InternalType\AbstractTypeObject::TYPE_DICTIONARY) { if (($resource->Type === null || $resource->Type->value == 'Action') && $resource->S !== null) { // It's a well-formed action, load it return Action\AbstractAction::load($resource); } elseif ($resource->D !== null) { // It's a destination $resource = $resource->D; } else { throw new Exception\CorruptedPdfException('Wrong resource type.'); } } if ($resource->getType() == InternalType\AbstractTypeObject::TYPE_ARRAY || $resource->getType() == InternalType\AbstractTypeObject::TYPE_NAME || $resource->getType() == InternalType\AbstractTypeObject::TYPE_STRING) { // Resource is an array, just treat it as an explicit destination array return Destination\AbstractDestination::load($resource); } else { throw new Exception\CorruptedPdfException('Wrong resource type.'); } }
/** * Annotation object constructor * * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $annotationDictionary) { if ($annotationDictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('Annotation dictionary resource has to be a dictionary.'); } $this->_annotationDictionary = $annotationDictionary; if ($this->_annotationDictionary->Type !== null && $this->_annotationDictionary->Type->value != 'Annot') { throw new Exception\CorruptedPdfException('Wrong resource type. \'Annot\' expected.'); } if ($this->_annotationDictionary->Rect === null) { throw new Exception\CorruptedPdfException('\'Rect\' dictionary entry is required.'); } if (count($this->_annotationDictionary->Rect->items) != 4 || $this->_annotationDictionary->Rect->items[0]->getType() != InternalType\AbstractTypeObject::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[1]->getType() != InternalType\AbstractTypeObject::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[2]->getType() != InternalType\AbstractTypeObject::TYPE_NUMERIC || $this->_annotationDictionary->Rect->items[3]->getType() != InternalType\AbstractTypeObject::TYPE_NUMERIC) { throw new Exception\CorruptedPdfException('\'Rect\' dictionary entry must be an array of four numeric elements.'); } }
/** * Create PDF outline object using specified dictionary * * @internal * @param \ZendPdf\InternalType\AbstractTypeObject $dictionary (It's actually Dictionary or Dictionary Object or Reference to a Dictionary Object) * @param \ZendPdf\Action\AbstractAction $parentAction * @param SplObjectStorage $processedOutlines List of already processed Outline dictionaries, * used to avoid cyclic references * @return \ZendPdf\Action\AbstractAction * @throws \ZendPdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $dictionary, \SplObjectStorage $processedDictionaries = null) { if ($dictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('$dictionary mast be an indirect dictionary object.'); } if ($processedDictionaries === null) { $processedDictionaries = new \SplObjectStorage(); } $processedDictionaries->attach($dictionary); $this->_outlineDictionary = $dictionary; if ($dictionary->Count !== null) { if ($dictionary->Count->getType() != InternalType\AbstractTypeObject::TYPE_NUMERIC) { throw new Exception\CorruptedPdfException('Outline dictionary Count entry must be a numeric element.'); } $childOutlinesCount = $dictionary->Count->value; if ($childOutlinesCount > 0) { $this->_open = true; } $childOutlinesCount = abs($childOutlinesCount); $childDictionary = $dictionary->First; for ($count = 0; $count < $childOutlinesCount; $count++) { if ($childDictionary === null) { throw new Exception\CorruptedPdfException('Outline childs load error.'); } if (!$processedDictionaries->contains($childDictionary)) { $this->childOutlines[] = new Loaded($childDictionary, $processedDictionaries); } $childDictionary = $childDictionary->Next; } if ($childDictionary !== null) { throw new Exception\CorruptedPdfException('Outline childs load error.'); } $this->_originalChildOutlines = $this->childOutlines; } }
/** * Return type of the element. * * @return integer */ public function getType() { return $this->_value->getType(); }
/** * Load PDF action object using specified dictionary * * @internal * @param \ZendPdf\InternalType\AbstractTypeObject $dictionary (It's actually Dictionary or Dictionary Object or Reference to a Dictionary Object) * @param SplObjectStorage $processedActions list of already processed action dictionaries, used to avoid cyclic references * @return \ZendPdf\Action\AbstractAction * @throws \ZendPdf\Exception\ExceptionInterface */ public static function load(InternalType\AbstractTypeObject $dictionary, \SplObjectStorage $processedActions = null) { if ($processedActions === null) { $processedActions = new \SplObjectStorage(); } if ($dictionary->getType() != InternalType\AbstractTypeObject::TYPE_DICTIONARY) { throw new Exception\CorruptedPdfException('$dictionary mast be a direct or an indirect dictionary object.'); } if (isset($dictionary->Type) && $dictionary->Type->value != 'Action') { throw new Exception\CorruptedPdfException('Action dictionary Type entry must be set to \'Action\'.'); } if ($dictionary->S === null) { throw new Exception\CorruptedPdfException('Action dictionary must contain S entry'); } switch ($dictionary->S->value) { case 'GoTo': return new GoToAction($dictionary, $processedActions); case 'GoToR': return new GoToR($dictionary, $processedActions); case 'GoToE': return new GoToE($dictionary, $processedActions); case 'Launch': return new Launch($dictionary, $processedActions); case 'Thread': return new Thread($dictionary, $processedActions); case 'URI': return new Uri($dictionary, $processedActions); case 'Sound': return new Sound($dictionary, $processedActions); case 'Movie': return new Movie($dictionary, $processedActions); case 'Hide': return new Hide($dictionary, $processedActions); case 'Named': return new Named($dictionary, $processedActions); case 'SubmitForm': return new SubmitForm($dictionary, $processedActions); case 'ResetForm': return new ResetForm($dictionary, $processedActions); case 'ImportData': return new ImportData($dictionary, $processedActions); case 'JavaScript': return new JavaScript($dictionary, $processedActions); case 'SetOCGState': return new SetOCGState($dictionary, $processedActions); case 'Rendition': return new Rendition($dictionary, $processedActions); case 'Trans': return new Trans($dictionary, $processedActions); case 'GoTo3DView': return new GoTo3DView($dictionary, $processedActions); default: return new Unknown($dictionary, $processedActions); } }