SetaPDF Demos

There seems to be a problem loading the components. Please check your PHP error logs for details!

Common issues could be that you missed to install the trial license or that you are using a trial version on an unsupported PHP version.

Add Named Destinations

This demo adds named destinations to imported PDF files or pages.
These destinations can be compared to anchors in HTML and they can be accessed internally (through e.g. actions) or by most PDF viewer through the hash of an URL.

PHP
<?php

// load and register the autoload function
require_once __DIR__ . '/../../../../../bootstrap.php';

// display some links to the named destinations to have some interactivity in this demo
if (!isset($_GET['e'])) {
    echo '<html><head><link rel="stylesheet" type="text/css" href="' . $basePath . 'layout/demo.css"/></head><body><div id="demoInput">';

    foreach (['product-1', 'product-2', 'product-3'] as $destination) {
        echo '<a href="?e=1#' . $destination . '" target="pdfFrame">Named Destination "' . $destination . '"</a><br/>';
    }

    echo '</div><iframe width="100%" name="pdfFrame" src="about:blank"/></body></html>';
    die();
}

// create a merger instance
$merger = new \SetaPDF_Merger();

// add the first file and add a named destination named "product-1"
$merger->addFile(
    $assetsDirectory . '/pdfs/tektown/products/Boombastic-Box.pdf',
    \SetaPDF_Merger::PAGES_ALL,
    'product-1'
);

// add page 2 of another file and add a named destination named "product-2"
$merger->addFile(
    $assetsDirectory . '/pdfs/tektown/products/All.pdf',
    2,
    'product-2'
);

// add page 3 of another file and add a named destination named "product-3"
$merger->addFile(
    // it is also possible to pass an array with named arguments
    [
        'filename' => $assetsDirectory . '/pdfs/tektown/products/All.pdf',
        'pages' => 3,
        'name' => 'product-3'
    ]
);

$merger->merge();

// get access to the document instance
$document = $merger->getDocument();
// set a writer instance
$document->setWriter(new \SetaPDF_Core_Writer_Http('merged-with-named-destinations.pdf', true));
// and save the result to the writer
$document->save()->finish();