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 SetaPDF_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
      require_once('library/SetaPDF/Autoload.php');
      
      $merger = new SetaPDF_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' => [
              SetaPDF_Merger::DESTINATION_NAME => 'product-B',
              SetaPDF_Merger::DESTINATION_FIT_MODE => [
                  SetaPDF_Core_Document_Destination::FIT_MODE_XYZ, 20, 750, 4
              ]
          ]
      ]);
      
      $merger->addFile([
          'filename' => 'files/pdfs/camtown/products/Noisy-Tube.pdf',
          'nameConfig' => [SetaPDF_Merger::DESTINATION_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):