Several Signatures
This demo shows you how to add more than one signature. This is simply done by restarting the whole process and use a new signature field.
PHP
use setasign\SetaPDF2\Core\Document; use setasign\SetaPDF2\Core\Writer\HttpWriter; use setasign\SetaPDF2\Core\Writer\StringWriter; use setasign\SetaPDF2\Signer\Signature\Module\Pades as PadesModule; use setasign\SetaPDF2\Signer\Signer; // load and register the autoload function require_once __DIR__ . '/../../../../../bootstrap.php'; // create a temporary writer $tempWriter = new StringWriter(); $document = Document::loadByFilename( $assetsDirectory . '/pdfs/camtown/Laboratory-Report.pdf', $tempWriter ); // create a signer instance $signer = new Signer($document); // add a signature field $field = $signer->addSignatureField(); // and define that you want to use this field $signer->setSignatureFieldName($field->getQualifiedName()); $certificatePath = $assetsDirectory . '/certificates/setapdf-no-pw.pem'; // now create a signature module $module = new PadesModule(); // pass the path to the certificate $module->setCertificate('file://' . $certificatePath); $module->setPrivateKey('file://' . $certificatePath, ''); // sign the document with the module $signer->sign($module); // now simply re-start the process // create the final writer $writer = new HttpWriter('several-signatures.pdf'); // create a new document instance based on the temporary result $document = Document::loadByString($tempWriter, $writer); // create a signer instance $signer = new Signer($document); // add a signature field $field = $signer->addSignatureField(); // and define that you want to use this field $signer->setSignatureFieldName($field->getQualifiedName()); $certificatePath = $assetsDirectory . '/certificates/setapdf-no-pw.pem'; // now create a signature module $module = new PadesModule(); // pass the path to the certificate $module->setCertificate('file://' . $certificatePath); $module->setPrivateKey('file://' . $certificatePath, ''); // sign the document and send the final document to the initial writer $signer->sign($module);