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); } }
public function testCreate() { $pdf = new Pdf\PdfDocument(); $page1 = $pdf->newPage(Pdf\Page::SIZE_A4); $page2 = $pdf->newPage(Pdf\Page::SIZE_A4); $destination = Destination\Zoom::create($page2, 0, 842, 0.5); $this->assertTrue($destination instanceof Destination\Zoom); $this->assertEquals($destination->getResource()->toString(), '[4 0 R /XYZ 0 842 0.5 ]'); $destination = Destination\Fit::create($page2); $this->assertTrue($destination instanceof Destination\Fit); $this->assertEquals($destination->getResource()->toString(), '[4 0 R /Fit ]'); $destination = Destination\FitHorizontally::create($page2, 842); $this->assertTrue($destination instanceof Destination\FitHorizontally); $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitH 842 ]'); $destination = Destination\FitVertically::create(2, 0); $this->assertTrue($destination instanceof Destination\FitVertically); $this->assertEquals($destination->getResource()->toString(), '[2 /FitV 0 ]'); $destination = Destination\FitRectangle::create($page1, 0, 10, 595, 842); $this->assertTrue($destination instanceof Destination\FitRectangle); $this->assertEquals($destination->getResource()->toString(), '[3 0 R /FitR 0 10 595 842 ]'); $destination = Destination\FitBoundingBox::create(1); $this->assertTrue($destination instanceof Destination\FitBoundingBox); $this->assertEquals($destination->getResource()->toString(), '[1 /FitB ]'); $destination = Destination\FitBoundingBoxHorizontally::create($page2, 842); $this->assertTrue($destination instanceof Destination\FitBoundingBoxHorizontally); $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBH 842 ]'); $destination = Destination\FitBoundingBoxVertically::create($page2, 0); $this->assertTrue($destination instanceof Destination\FitBoundingBoxVertically); $this->assertEquals($destination->getResource()->toString(), '[4 0 R /FitBV 0 ]'); }