// Replace the Prefix in the decimal labels (from example 1). $label = $doc->GetPageLabel(4); if ($label->IsValid()) { $label->SetPrefix("A"); $label->SetStart(1); } // Add a new label $new_label = PageLabel::Create($doc->GetSDFDoc(), PageLabel::e_decimal, "B", 1); $doc->SetPageLabel(10, $new_label); // starting from page 10. $doc->Save($output_path . "newsletter_with_pagelabels_modified.pdf", SDFDoc::e_linearized); echo nl2br("Done. Result saved in newsletter_with_pagelabels_modified.pdf...\n"); $page_num = $doc->GetPageCount(); for ($i = 1; $i <= $page_num; ++$i) { echo "Page number: " . $i; $label = $doc->GetPageLabel($i); if ($label->IsValid()) { echo nl2br(" Label: " . $label->GetLabelTitle($i) . "\n"); } else { echo nl2br(" No Label.\n"); } } $doc->Close(); //----------------------------------------------------------- // Example 4: Delete all page labels in an existing PDF document. //----------------------------------------------------------- $doc = new PDFDoc($output_path . "newsletter_with_pagelabels.pdf"); $doc->GetRoot()->Erase("PageLabels"); $doc->Save($output_path . "newsletter_with_pagelabels_removed.pdf", SDFDoc::e_linearized); echo nl2br("Done. Result saved in newsletter_with_pagelabels_removed.pdf...\n"); // ...
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; }