/** * Object constructor * * @param \Zend\Pdf\InternalType\DictionaryObject $dictionary * @param SplObjectStorage $processedActions list of already processed action dictionaries, * used to avoid cyclic references * @throws \Zend\Pdf\Exception\ExceptionInterface */ public function __construct(InternalType\AbstractTypeObject $dictionary, \SplObjectStorage $processedActions) { parent::__construct($dictionary, $processedActions); if ($dictionary->URI === null) { throw new Exception\CorruptedPdfException('URI action dictionary entry is required'); } }
/** * Parse resource and return it as an Action or Explicit Destination * * $param \Zend\Pdf\InternalType $resource * @return \Zend\Pdf\Destination\AbstractDestination|\Zend\Pdf\Action\AbstractAction * @throws \Zend\Pdf\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.'); } }
public function testActionURILoad2() { $dictionary = new InternalType\DictionaryObject(); $dictionary->Type = new InternalType\NameObject('Action'); $dictionary->S = new InternalType\NameObject('URI'); try { $action = Action\AbstractAction::load($dictionary); $this->fail("exception expected"); } catch (Pdf\Exception $e) { $this->assertContains('URI action dictionary entry is required', $e->getMessage()); } }
/** * Get link annotation destination * * @return \Zend\Pdf\InternalStructure\NavigationTarget|null */ public function getDestination() { if ($this->_annotationDictionary->Dest === null && $this->_annotationDictionary->A === null) { return null; } if ($this->_annotationDictionary->Dest !== null) { return Destination\AbstractDestination::load($this->_annotationDictionary->Dest); } else { return Pdf\Action\AbstractAction::load($this->_annotationDictionary->A); } }
/** * Object constructor * * @param \Zend\Pdf\InternalType\DictionaryObject $dictionary * @param SplObjectStorage $processedActions list of already processed action dictionaries, * used to avoid cyclic references */ public function __construct(InternalType\AbstractTypeObject $dictionary, \SplObjectStorage $processedActions) { parent::__construct($dictionary, $processedActions); $this->_destination = Destination\AbstractDestination::load($dictionary->D); }
public function testActionURILoad2() { $dictionary = new InternalType\DictionaryObject(); $dictionary->Type = new InternalType\NameObject('Action'); $dictionary->S = new InternalType\NameObject('URI'); $this->setExpectedException('\\Zend\\Pdf\\Exception\\CorruptedPdfException', 'URI action dictionary entry is required'); $action = Action\AbstractAction::load($dictionary); }
/** * Walk through action and its chained actions tree and remove nodes * if they are GoTo actions with an unresolved target. * * Returns null if root node is deleted or updated action overwise. * * @todo Give appropriate name and make method public * * @param \Zend\Pdf\Action\AbstractAction $action * @param boolean $refreshPagesHash Refresh page collection hashes before processing * @return \Zend\Pdf\Action\AbstractAction|null */ protected function _cleanUpAction(Action\AbstractAction $action, $refreshPageCollectionHashes = true) { if ($this->_pageReferences === null || $refreshPageCollectionHashes) { $this->_refreshPagesHash(); } // Named target is an action if ($action instanceof Action\GoToAction && $this->resolveDestination($action->getDestination(), false) === null) { // Action itself is a GoTo action with an unresolved destination return null; } // Walk through child actions $iterator = new \RecursiveIteratorIterator($action, \RecursiveIteratorIterator::SELF_FIRST); $actionsToClean = array(); $deletionCandidateKeys = array(); foreach ($iterator as $chainedAction) { if ($chainedAction instanceof Action\GoToAction && $this->resolveDestination($chainedAction->getDestination(), false) === null) { // Some child action is a GoTo action with an unresolved destination // Mark it as a candidate for deletion $actionsToClean[] = $iterator->getSubIterator(); $deletionCandidateKeys[] = $iterator->getSubIterator()->key(); } } foreach ($actionsToClean as $id => $action) { unset($action->next[$deletionCandidateKeys[$id]]); } return $action; }
/** * Get outline target. * * @return \Zend\Pdf\InternalStructure\NavigationTarget * @throws \Zend\Pdf\Exception */ public function getTarget() { if ($this->_outlineDictionary->Dest !== null) { if ($this->_outlineDictionary->A !== null) { throw new Exception\CorruptedPdfException('Outline dictionary may contain Dest or A entry, but not both.'); } return Destination\AbstractDestination::load($this->_outlineDictionary->Dest); } else { if ($this->_outlineDictionary->A !== null) { return Action\AbstractAction::load($this->_outlineDictionary->A); } } return null; }