Named Destinations

Table of Contents

  1. Introduction
    1. Example

      Introduction

      The addFile() and addDocument() methods accept a name for a named destination in their $name parameter.

      This way it is possible to access the desired page by this name. 

      Example

      This named destination could be used in an URI to open the document at the specific page.

      PHP
      <?php
      require_once('library/SetaPDF/Autoload.php');
      
      $merger = new SetaPDF_Merger();
      // add files from the file system
      $merger->addFile(array(
          'filename' => 'files/pdfs/camtown/products/Boombastic-Box.pdf',
          'name' => 'product-A'
      ));
      
      $merger->addFile(array(
          'filename' => 'files/pdfs/camtown/products/Fantastic-Speaker.pdf',
          'name' => 'product-B'
      ));
      
      $merger->addFile(array(
          'filename' => 'files/pdfs/camtown/products/Noisy-Tube.pdf',
          'name' => 'product-C'
      ));
      
      // merge them together
      $merger->merge();
      
      // get the resulting document instance
      $document = $merger->getDocument();
      // add a writer
      $document->setWriter(new SetaPDF_Core_Writer_Http('named-destinations.pdf', true));
      // save and finish
      $document->save()->finish();

      To jump to the desired destinations see following URI examples that point to the above script (you need to view the document in your browser):