public function testProcessing()
 {
     $pdf = new Pdf\PdfDocument();
     $page1 = $pdf->newPage(Pdf\Page::SIZE_A4);
     $page2 = $pdf->newPage(Pdf\Page::SIZE_A4);
     $page3 = $pdf->newPage(Pdf\Page::SIZE_A4);
     // not actually included into pages array
     $pdf->pages[] = $page1;
     $pdf->pages[] = $page2;
     $this->assertTrue(count($pdf->getNamedDestinations()) == 0);
     $destination1 = Destination\Fit::create($page1);
     $destination2 = Destination\Fit::create($page2);
     $action1 = Action\GoToAction::create($destination1);
     $pdf->setNamedDestination('GoToPage1', $action1);
     $this->assertTrue($pdf->getNamedDestination('GoToPage1') === $action1);
     $this->assertTrue($pdf->getNamedDestination('GoToPage9') === null);
     $pdf->setNamedDestination('Page2', $destination2);
     $this->assertTrue($pdf->getNamedDestination('Page2') === $destination2);
     $this->assertTrue($pdf->getNamedDestination('Page9') === null);
     $pdf->setNamedDestination('Page1', $destination1);
     $pdf->setNamedDestination('Page1_1', Destination\Fit::create(1));
     $pdf->setNamedDestination('Page9_1', Destination\Fit::create(9));
     // will be egnored
     $action3 = Action\GoToAction::create(Destination\Fit::create($page3));
     $pdf->setNamedDestination('GoToPage3', $action3);
     $this->assertTrue(strpos($pdf->render(), '[(GoToPage1) <</Type /Action /S /GoTo /D [3 0 R /Fit ] >> (Page1) [3 0 R /Fit ] (Page1_1) [1 /Fit ] (Page2) [4 0 R /Fit ] ]') !== false);
 }
Example #2
0
 public function testGetDestination2()
 {
     $pdf = new Pdf\PdfDocument();
     $page1 = $pdf->newPage(Pdf\Page::SIZE_A4);
     $page2 = $pdf->newPage(Pdf\Page::SIZE_A4);
     $page3 = $pdf->newPage(Pdf\Page::SIZE_A4);
     // Page created, but not included into pages list
     $pdf->pages[] = $page1;
     $pdf->pages[] = $page2;
     $action1 = Action\GoToAction::create(Destination\Fit::create($page2));
     $action2 = Action\GoToAction::create(Destination\Fit::create($page3));
     $this->assertTrue($pdf->resolveDestination($action1->getDestination()) === $page2);
     $this->assertTrue($pdf->resolveDestination($action2->getDestination()) === null);
 }
Example #3
0
 public function addBookmark($identifier, $name, $top, $parentIdentifier = null)
 {
     try {
         $destination = \ZendPdf\Destination\FitHorizontally::create($this->getPage(), $top);
         $action = \ZendPdf\Action\GoToAction::create($destination);
         //convert from input encoding to UTF-16
         $name = iconv($this->encoding, 'UTF-16', $name);
         $outline = \ZendPdf\Outline\AbstractOutline::create($name, $action);
         $this->engine->registerOutline($identifier, $outline);
         $this->addToQueue('doAddBookmark', array($identifier, $outline, $parentIdentifier));
     } catch (\ZendPdf\Exception\ExceptionInterface $e) {
         throw new RuntimeException('Error while bookmark adding', 0, $e);
     }
 }