function CertifyPDF() { $infile = '../../TestFiles/newsletter.pdf'; $outfile = '../../TestFiles/Output/newsletter_certified.pdf'; $certfile = '../../TestFiles/pdftron.pfx'; $result = true; try { echo nl2br('Certifying PDF document: "' . $infile . '".' . PHP_EOL); // Open an existing PDF $doc = new PDFDoc($infile); // Add an StdSignatureHandler instance to PDFDoc, making sure to keep track of it using the ID returned. $sigHandlerId = $doc->AddStdSignatureHandler($certfile, "password"); // Create a new signature form field in the PDFDoc. $sigField = $doc->FieldCreate('Signature1', Field::e_signature); // Assign the form field as an annotation widget to the PDFDoc so that a signature appearance can be added. $page1 = $doc->GetPage(1); $widgetAnnot = Widget::Create($doc->GetSDFDoc(), new Rect(0.0, 0.0, 0.0, 0.0), $sigField); $page1->AnnotPushBack($widgetAnnot); $widgetAnnot->SetPage($page1); $widgetObj = $widgetAnnot->GetSDFObj(); $widgetObj->PutNumber('F', 132.0); $widgetObj->PutName('Type', 'Annot'); // Tell PDFNetC to use the SignatureHandler created to sign the new signature form field. $sigDict = $sigField->UseSignatureHandler($sigHandlerId); // Add more information to the signature dictionary. $sigDict->PutName('SubFilter', 'adbe.pkcs7.detached'); $sigDict->PutString('Name', 'PDFTron'); $sigDict->PutString('Location', 'Vancouver, BC'); $sigDict->PutString('Reason', 'Document verification.'); // Appearance can be added to the widget annotation. Please see the "SignPDF()" function for details. // Add this sigDict as DocMDP in Perms dictionary from root $root = $doc->GetRoot(); $perms = $root->PutDict('Perms'); // add the sigDict as DocMDP (indirect) in Perms $perms->Put('DocMDP', $sigDict); // add the additional DocMDP transform params $refObj = $sigDict->PutArray("Reference"); $transform = $refObj->PushBackDict(); $transform->PutName("TransformMethod", "DocMDP"); $transform->PutName("Type", "SigRef"); $transformParams = $transform->PutDict("TransformParams"); $transformParams->PutNumber("P", 1); // Set permissions as necessary. $transformParams->PutName("Type", "TransformParams"); $transformParams->PutName("V", "1.2"); // Save the PDFDoc. Once the method below is called, PDFNetC will also sign the document using the information // provided. $doc->Save($outfile, 0); echo nl2br('Finished certifying PDF document' . PHP_EOL); $doc->Close(); } catch (Exception $e) { echo nl2br($e->getMessage() . PHP_EOL); echo nl2br($e->getTraceAsString() . PHP_EOL); $result = false; } return $result; }