Named Destinations

Table of Contents

  1. Introduction
    1. Example

      Introduction

      The addFile() and addDocument() methods accept a name and/or its configuration as an array for a named destination in their $nameConfig parameter.

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

      Before revision 1330 this paramter only accepts a simple string and was named $name. It was renamed to $nameConfig and accepts an array now. In this array you can pass the name and the fitMode configuration, which is an additional array which will be forwarded to the \setasign\SetaPDF2\Core\Document\Destination::createDestinationArray() method internally. This allows you more control above the created destination. 

      Example

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

      PHP
      <?php
      
      use setasign\SetaPDF2\Core\Document\Destination;
      use setasign\SetaPDF2\Core\Writer\HttpWriter;
      use setasign\SetaPDF2\Merger\Merger;
      
      require_once('library/SetaPDF/Autoload.php');
      
      $merger = new Merger();
      // add files from the file system
      $merger->addFile([
          'filename' => 'files/pdfs/camtown/products/Boombastic-Box.pdf',
          'name' => 'product-A' // works for backwards compatibility
      ]);
      
      $merger->addFile([
          'filename' => 'files/pdfs/camtown/products/Fantastic-Speaker.pdf',
          'nameConfig' => [
              Merger::DESTINATION_NAME => 'product-B',
              Merger::DESTINATION_FIT_MODE => [
                  Destination::FIT_MODE_XYZ, 20, 750, 4
              ]
          ]
      ]);
      
      $merger->addFile([
          'filename' => 'files/pdfs/camtown/products/Noisy-Tube.pdf',
          'nameConfig' => [Merger::DESTINATION_NAME => 'product-C']
      ]);
      
      // merge them together
      $merger->merge();
      
      // get the resulting document instance
      $document = $merger->getDocument();
      // add a writer
      $document->setWriter(new HttpWriter('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):