Sign Several Times

Table of Contents

  1. Introduction
    1. Example

      Introduction

      Sometimes it is needed to sign a PDF document by several signees. The PDF format does not support parallel signatures but you have to simply restart the signature process for each signee. 

      Example

      To sign a PDF document several times you need to create intermediate versions of the document. Following example shows this as a manual process: 

      PHP
      <?php
      require_once('library/SetaPDF/Autoload.php');
      
      // create a temporary writer
      $tempWriter = new SetaPDF_Core_Writer_String();
      
      // create a new document instance
      $document = SetaPDF_Core_Document::loadByFilename(
          'files/pdfs/tektown/Laboratory-Report.pdf', $tempWriter
      );
      
      // create a signer instance
      $signer = new SetaPDF_Signer($document);
      
      // set some signature properties
      $signer->setReason('Testing');
      $signer->setLocation('SetaPDF-Signer Manual');
      
      // create a signature module
      $module = new SetaPDF_Signer_Signature_Module_OpenSsl();
      // load the certificate
      $certificate = 'file://files/certificates/setapdf-no-pw.pem';
      $module->setCertificate($certificate);
      $module->setPrivateKey(array($certificate, '' /* no password */));
      
      // sign the document and send the final document to the initial writer
      $signer->sign($module);
      
      // now simply re-start the process
      
      // create the final writer
      $writer = new SetaPDF_Core_Writer_Http('several-signatures.pdf', true);
      
      // create a new document instance based on the temporary result
      $document = SetaPDF_Core_Document::loadByString($tempWriter, $writer);
      
      // create a signer instance
      $signer = new SetaPDF_Signer($document);
      
      // set a new signature field name
      $signer->setSignatureFieldName('Signature 2');
      
      // set some signature properties
      $signer->setReason('Also testing');
      $signer->setLocation('SetaPDF-Signer Manual');
      
      // create a signature module
      $module = new SetaPDF_Signer_Signature_Module_OpenSsl();
      // load the certificate
      $certificate = 'file://files/certificates/setapdf-no-pw.pem';
      $module->setCertificate($certificate);
      $module->setPrivateKey(array($certificate, '' /* no password */));
      
      // sign the document and send the final document to the initial writer
      $signer->sign($module);