Table of Contents

  1. Introduction
    1. Example


      The PDF specification comes with a feature called Optional Content that will allow you to group content. A groups visibility can be controlled in various ways. The Core component offers classes to handle them at a very low level. A common way to turn a visibility on and off is the Layer pannel in a Reader application.

      The Merger component will import optional content groups by default, too. It can be controlled by the last parameter of the  addFile() and addDocument() methods.


      The example will merge two document that make use of layers while leaving the layer information of the second document. The original documents can be seen here and here

      $merger = new \SetaPDF_Merger();
      // add a file with layer definition
      // add a file with layer definition but do not import the content groupd
          'filename' => 'files/pdfs/layers/rect+circle+polygon.pdf',
          'copyLayers' => false
      // merge them together
      // get the resulting document instance
      $document = $merger->getDocument();
      // open the optional content panel by default
      // add a writer
      $document->setWriter(new \SetaPDF_Core_Writer_Http('outline-1.pdf', true));
      // save and finish