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; }
$writer->WriteElement($build->CreateTextEnd()); $stm = $writer->End(); // Set the bounding box $stm->PutRect("BBox", 0, 0, 101, 37); $stm->PutName("Subtype", "Form"); return $stm; } PDFNet::Initialize(); //---------------------------------------------------------------------------------- // Example 1: Programatically create new Form Fields and Widget Annotations. //---------------------------------------------------------------------------------- $doc = new PDFDoc(); $blank_page = $doc->PageCreate(); // Create a blank new page and add some form fields. // Create new fields. $emp_first_name = $doc->FieldCreate("employee.name.first", Field::e_text, "John", ""); $emp_last_name = $doc->FieldCreate("employee.name.last", Field::e_text, "Doe", ""); $emp_last_check1 = $doc->FieldCreate("employee.name.check1", Field::e_check, "Yes", ""); $submit = $doc->FieldCreate("submit", Field::e_button); // Create page annotations for the above fields. // Create text annotations $annot1 = Widget::Create($doc->GetSDFDoc(), new Rect(50.0, 550.0, 350.0, 600.0), $emp_first_name); $annot2 = Widget::Create($doc->GetSDFDoc(), new Rect(50.0, 450.0, 350.0, 500.0), $emp_last_name); // Create a check-box annotation $annot3 = Widget::Create($doc->GetSDFDoc(), new Rect(64.0, 356.0, 120.0, 410.0), $emp_last_check1); // Set the annotation appearance for the "Yes" state... $annot3->SetAppearance(CreateCheckmarkAppearance($doc, Annot::e_normal, "Yes")); // Create button annotation $annot4 = Widget::Create($doc->GetSDFDoc(), new Rect(64.0, 284.0, 163.0, 320.0), $submit); // Set the annotation appearances for the down and up state... $annot4->SetAppearance(CreateButtonAppearance($doc, false), Annot::e_normal);