Type = new Zend_Pdf_Element_Name('Action'); $dictionary->S = new Zend_Pdf_Element_Name('GoTo'); $dictionary->D = new Zend_Pdf_Element_String('SomeNamedDestination'); $action2Dictionary = new Zend_Pdf_Element_Dictionary(); $action2Dictionary->Type = new Zend_Pdf_Element_Name('Action'); $action2Dictionary->S = new Zend_Pdf_Element_Name('Thread'); $action2Dictionary->D = new Zend_Pdf_Element_String('NamedDestination 2'); $action2Dictionary->Next = new Zend_Pdf_Element_Array(); $dictionary->Next = $action2Dictionary; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoTo'); $leafAction->D = new Zend_Pdf_Element_String('NamedDestination 3'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoToR'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoToE'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Launch'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Thread'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('URI'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Sound'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Movie'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Hide'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Named'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('SubmitForm'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('ResetForm'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('ImportData'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('JavaScript'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('SetOCGState'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Rendition'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Trans'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoTo3DView'); $action2Dictionary->Next->items[] = $leafAction; $action = Zend_Pdf_Action::load($dictionary); $actionsCount = 0; $iterator = new RecursiveIteratorIterator(new Zend_Pdf_RecursivelyIteratableObjectsContainer(array($action)), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $chainedAction) { $actionsCount++; } $this->assertEquals(20, $actionsCount); } public function testExtract() { $dictionary = new Zend_Pdf_Element_Dictionary(); $dictionary->Type = new Zend_Pdf_Element_Name('Action'); $dictionary->S = new Zend_Pdf_Element_Name('GoToR'); $dictionary->D = new Zend_Pdf_Element_String('SomeNamedDestination'); $action2Dictionary = new Zend_Pdf_Element_Dictionary(); $action2Dictionary->Type = new Zend_Pdf_Element_Name('Action'); $action2Dictionary->S = new Zend_Pdf_Element_Name('Thread'); $action2Dictionary->D = new Zend_Pdf_Element_String('NamedDestination 2'); $action2Dictionary->Next = new Zend_Pdf_Element_Array(); $dictionary->Next = $action2Dictionary; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoTo'); $leafAction->D = new Zend_Pdf_Element_String('NamedDestination 3'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoToR'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoToE'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Launch'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Thread'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('URI'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Sound'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Movie'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Hide'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Named'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('SubmitForm'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('ResetForm'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('ImportData'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('JavaScript'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('SetOCGState'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Rendition'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('Trans'); $action2Dictionary->Next->items[] = $leafAction; $leafAction = new Zend_Pdf_Element_Dictionary(); $leafAction->Type = new Zend_Pdf_Element_Name('Action'); $leafAction->S = new Zend_Pdf_Element_Name('GoTo3DView'); $action2Dictionary->Next->items[] = $leafAction; $action = Zend_Pdf_Action::load($dictionary); $actionsToClean = array(); $deletionCandidateKeys = array(); $iterator = new RecursiveIteratorIterator($action, RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $chainedAction) { if ($chainedAction instanceof Zend_Pdf_Action_GoTo) { $actionsToClean[] = $iterator->getSubIterator(); $deletionCandidateKeys[] = $iterator->getSubIterator()->key(); } } foreach ($actionsToClean as $id => $action) { unset($action->next[$deletionCandidateKeys[$id]]); } $actionsCount = 0; $iterator = new RecursiveIteratorIterator(new Zend_Pdf_RecursivelyIteratableObjectsContainer(array($action)), RecursiveIteratorIterator::SELF_FIRST); foreach ($iterator as $chainedAction) { $actionsCount++; } $this->assertEquals(18, $actionsCount); $action->dumpAction(new Zend_Pdf_ElementFactory(1)); $this->assertEquals( $action->getResource()->toString(), '<>'); } public function testCreate() { $action1 = Zend_Pdf_Action_GoTo::create('SomeNamedDestination'); $action1->next[] = Zend_Pdf_Action_GoTo::create('AnotherNamedDestination'); $action1->dumpAction(new Zend_Pdf_ElementFactory(1)); $this->assertEquals($action1->getResource()->toString(), '<>'); } public function testCreate1() { $pdf = new Zend_Pdf(); $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); require_once 'Zend/Pdf/Destination/Fit.php'; $destination = Zend_Pdf_Destination_Fit::create($page2); $action = Zend_Pdf_Action_GoTo::create($destination); $action->dumpAction(new Zend_Pdf_ElementFactory(1)); $this->assertEquals($action->getResource()->toString(), '<>'); } public function testGetDestination() { $dictionary = new Zend_Pdf_Element_Dictionary(); $dictionary->Type = new Zend_Pdf_Element_Name('Action'); $dictionary->S = new Zend_Pdf_Element_Name('GoTo'); $dictionary->D = new Zend_Pdf_Element_String('SomeNamedDestination'); $action = Zend_Pdf_Action::load($dictionary); $this->assertEquals($action->getDestination()->getName(), 'SomeNamedDestination'); } public function testGetDestination2() { $pdf = new Zend_Pdf(); $page1 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $page2 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); $page3 = $pdf->newPage(Zend_Pdf_Page::SIZE_A4); // Page created, but not included into pages list $pdf->pages[] = $page1; $pdf->pages[] = $page2; require_once 'Zend/Pdf/Destination/Fit.php'; $action1 = Zend_Pdf_Action_GoTo::create(Zend_Pdf_Destination_Fit::create($page2)); $action2 = Zend_Pdf_Action_GoTo::create(Zend_Pdf_Destination_Fit::create($page3)); $this->assertTrue($pdf->resolveDestination($action1->getDestination()) === $page2); $this->assertTrue($pdf->resolveDestination($action2->getDestination()) === null); } }