Skip to content

Commit

Permalink
Create test-file
Browse files Browse the repository at this point in the history
  • Loading branch information
JanSlabon committed Dec 6, 2023
1 parent f63773c commit 68a894e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Binary file not shown.
42 changes: 42 additions & 0 deletions tests/_files/pdfs/links/update-links.pdf.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/* A simple helper script to modify links.pdf in view to indirect references in annotation dictionaries.
* We used SetaPDF-Core for doing such low-level modifications.
*/

require_once __DIR__ . '/../../../../../SetaPDF/library/SetaPDF/Autoload.php';

$writer = new SetaPDF_Core_Writer_File('links-with-indirect-references.pdf');
$document = SetaPDF_Core_Document::loadByFilename('links.pdf', $writer);

$pages = $document->getCatalog()->getPages();
$page = $pages->getPage(1);

$annotations = $page->getAnnotations();
$allAnnots = $annotations->getAll();

$dict = $allAnnots[0]->getDictionary();
$bs = $dict->getValue('BS');
$d = $bs->getValue('D');
$bs->offsetSet('D', $document->createNewObject($d));
$dict->offsetSet('BS', $document->createNewObject($bs));

$dict = $allAnnots[1]->getDictionary();
$c = $dict->getValue('C');
$object = $document->createNewObject($c);
$ref = new SetaPDF_Core_Type_IndirectReference($object, 0, $document);
$dict->offsetSet('C', $document->createNewObject($ref));


$dict = $allAnnots[5]->getDictionary();
$border = $dict->getValue('Border');
$dict->offsetSet('Border', $document->createNewObject($border));

$page = $pages->getPage(2);
$annotations = $page->getAnnotations();
$allAnnots = $annotations->getAll();

$dict = $allAnnots[0]->getDictionary();
$rect = $dict->getValue('Rect');
$dict->offsetSet('Rect', $document->createNewObject($rect));

$document->save()->finish();

0 comments on commit 68a894e

Please sign in to comment.