/** * Set goto action destination * * @param \Zend\Pdf\Destination\AbstractDestination|string $destination * @return \Zend\Pdf\Action\GoToAction */ public function setDestination(Destination\AbstractDestination $destination) { $this->_destination = $destination; $this->_actionDictionary->touch(); $this->_actionDictionary->D = $destination->getResource(); return $this; }
/** * 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.'); } }
/** * 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); } }
public function testGettersSetters() { $pdf = new Pdf\PdfDocument(); $page1 = $pdf->newPage(Pdf\Page::SIZE_A4); $page2 = $pdf->newPage(Pdf\Page::SIZE_A4); // \Zend\Pdf\Destination\Zoom $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('XYZ'); $destArray->items[] = new InternalType\NumericObject(0); // left $destArray->items[] = new InternalType\NumericObject(842); // top $destArray->items[] = new InternalType\NumericObject(1); // zoom $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getLeftEdge(), 0); $destination->setLeftEdge(5); $this->assertEquals($destination->getLeftEdge(), 5); $this->assertEquals($destination->getTopEdge(), 842); $destination->setTopEdge(825); $this->assertEquals($destination->getTopEdge(), 825); $this->assertEquals($destination->getZoomFactor(), 1); $destination->setZoomFactor(0.5); $this->assertEquals($destination->getZoomFactor(), 0.5); // \Zend\Pdf\Destination\FitHorizontally $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('FitH'); $destArray->items[] = new InternalType\NumericObject(842); // top $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getTopEdge(), 842); $destination->setTopEdge(825); $this->assertEquals($destination->getTopEdge(), 825); // \Zend\Pdf\Destination\FitVertically $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('FitV'); $destArray->items[] = new InternalType\NumericObject(0); // left $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getLeftEdge(), 0); $destination->setLeftEdge(5); $this->assertEquals($destination->getLeftEdge(), 5); // \Zend\Pdf\Destination\FitRectangle $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('FitR'); $destArray->items[] = new InternalType\NumericObject(0); // left $destArray->items[] = new InternalType\NumericObject(10); // bottom $destArray->items[] = new InternalType\NumericObject(595); // right $destArray->items[] = new InternalType\NumericObject(842); // top $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getLeftEdge(), 0); $destination->setLeftEdge(5); $this->assertEquals($destination->getLeftEdge(), 5); $this->assertEquals($destination->getBottomEdge(), 10); $destination->setBottomEdge(20); $this->assertEquals($destination->getBottomEdge(), 20); $this->assertEquals($destination->getRightEdge(), 595); $destination->setRightEdge(590); $this->assertEquals($destination->getRightEdge(), 590); $this->assertEquals($destination->getTopEdge(), 842); $destination->setTopEdge(825); $this->assertEquals($destination->getTopEdge(), 825); // \Zend\Pdf\Destination\FitBoundingBoxHorizontally $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('FitBH'); $destArray->items[] = new InternalType\NumericObject(842); // top $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getTopEdge(), 842); $destination->setTopEdge(825); $this->assertEquals($destination->getTopEdge(), 825); // \Zend\Pdf\Destination\FitBoundingBoxVertically $destArray = new InternalType\ArrayObject(); $destArray->items[] = $page2->getPageDictionary(); $destArray->items[] = new InternalType\NameObject('FitBV'); $destArray->items[] = new InternalType\NumericObject(0); // left $destination = Destination\AbstractDestination::load($destArray); $this->assertEquals($destination->getLeftEdge(), 0); $destination->setLeftEdge(5); $this->assertEquals($destination->getLeftEdge(), 5); }
/** * Resolve destination. * * Returns \Zend\Pdf\Page page object or null if destination is not found within PDF document. * * @param \Zend\Pdf\Destination\AbstractDestination $destination Destination to resolve * @param boolean $refreshPagesHash Refresh page collection hashes before processing * @return \Zend\Pdf\Page|null * @throws \Zend\Pdf\Exception */ public function resolveDestination(Destination\AbstractDestination $destination, $refreshPageCollectionHashes = true) { if ($this->_pageReferences === null || $refreshPageCollectionHashes) { $this->_refreshPagesHash(); } if ($destination instanceof Destination\Named) { if (!isset($this->_namedTargets[$destination->getName()])) { return null; } $destination = $this->getNamedDestination($destination->getName()); if ($destination instanceof Action\AbstractAction) { if (!$destination instanceof Action\GoToAction) { return null; } $destination = $destination->getDestination(); } if (!$destination instanceof Destination\Explicit) { throw new Exception\CorruptedPdfException('Named destination target has to be an explicit destination.'); } } // Named target is an explicit destination $pageElement = $destination->getResource()->items[0]; if ($pageElement->getType() == InternalType\AbstractTypeObject::TYPE_NUMERIC) { // Page reference is a PDF number if (!isset($this->_pageNumbers[$pageElement->value])) { return null; } return $this->_pageNumbers[$pageElement->value]; } // Page reference is a PDF page dictionary reference $pageDictionaryHashId = spl_object_hash($pageElement->getObject()); if (!isset($this->_pageReferences[$pageDictionaryHashId])) { return null; } return $this->_pageReferences[$pageDictionaryHashId]; }
/** * 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; }