Some test text!

Add a DocTimeStamp signaturekeyboard_arrow_down

Add a DocTimeStamp signature in PHP

To add a DocTimeStamp signature:

$doc = new PDFDoc($in_docpath);
$doctimestamp_signature_field = $doc->CreateDigitalSignatureField();
$tst_config = new TimestampingConfiguration("");
$opts = new VerificationOptions(VerificationOptions::e_compatibility_and_archiving);
/* It is necessary to add to the VerificationOptions a trusted root certificate corresponding to 
the chain used by the timestamp authority to sign the timestamp token, in order for the timestamp
response to be verifiable during DocTimeStamp signing. */
/* By default, we only check online for revocation of certificates using the newer and lighter 
OCSP protocol as opposed to CRL, due to lower resource usage and greater reliability. However, 
it may be necessary to enable online CRL revocation checking in order to verify some timestamps
(i.e. those that do not have an OCSP responder URL for all non-trusted certificates). */

$widgetAnnot = SignatureWidget::Create($doc, new Rect(0.0, 100.0, 200.0, 150.0), $doctimestamp_signature_field);

// (OPTIONAL) Add an appearance to the signature field.
$img = Image::Create($doc->GetSDFDoc(), $in_appearance_img_path);

echo(nl2br('Testing timestamping configuration.'.PHP_EOL));
$config_result = $tst_config->TestConfiguration($opts);
if ($config_result->GetStatus())
    echo(nl2br('Success: timestamping configuration usable. Attempting to timestamp.'.PHP_EOL));
    // Print details of timestamping failure.
    if ($config_result->HasResponseVerificationResult())
        $tst_result = $config_result->GetResponseVerificationResult();
        echo(nl2br('CMS digest status: '.$tst_result->GetCMSDigestStatusAsString().PHP_EOL));
        echo(nl2br('Message digest status: '.$tst_result->GetMessageImprintDigestStatusAsString().PHP_EOL));
        echo(nl2br('Trust status: '.$tst_result->GetTrustStatusAsString().PHP_EOL));
    return false;

$doctimestamp_signature_field->TimestampOnNextSave($tst_config, $opts);

// Save/signing throws if timestamping fails.
$doc->Save($in_outpath, SDFDoc::e_incremental);

Digital signatures
Full code sample which demonstrates using the digital signature API to digitally sign, certify, and/or verify PDF documents.

Get the answers you need: Support


Free Trial

Get unlimited trial usage of PDFTron SDK to bring accurate, reliable, and fast document processing capabilities to any application or workflow.

Select a platform to get started with your free trial.

Unlimited usage. No email address required.

Join our live demo to learn about use cases & capabilities for WebViewer

Learn more