Пример #1
0
 /**
  * Set goto action destination
  *
  * @param \ZendPdf\Destination\AbstractDestination|string $destination
  * @return \ZendPdf\Action\GoToAction
  */
 public function setDestination(Destination\AbstractDestination $destination)
 {
     $this->_destination = $destination;
     $this->_actionDictionary->touch();
     $this->_actionDictionary->D = $destination->getResource();
     return $this;
 }
Пример #2
0
 /**
  * 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.');
     }
 }
Пример #3
0
 /**
  * Get outline target.
  *
  * @return \ZendPdf\InternalStructure\NavigationTarget
  * @throws \ZendPdf\Exception\ExceptionInterface
  */
 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);
     } elseif ($this->_outlineDictionary->A !== null) {
         return Action\AbstractAction::load($this->_outlineDictionary->A);
     }
     return null;
 }
Пример #4
0
 public function testGettersSetters()
 {
     $pdf = new Pdf\PdfDocument();
     $page1 = $pdf->newPage(Pdf\Page::SIZE_A4);
     $page2 = $pdf->newPage(Pdf\Page::SIZE_A4);
     // \ZendPdf\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);
     // \ZendPdf\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);
     // \ZendPdf\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);
     // \ZendPdf\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);
     // \ZendPdf\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);
     // \ZendPdf\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);
 }
Пример #5
0
 /**
  * Get link annotation destination
  *
  * @return \ZendPdf\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);
     }
 }