Some test text!


Add a DocTimeStamp signature using JavaScript

Only available with the Full API

To add a DocTimeStamp signature:

const doc = await PDFNet.PDFDoc.createFromFilePath(in_docpath);
const doctimestamp_signature_field = await doc.createDigitalSignatureField();
const tst_config = await PDFNet.TimestampingConfiguration.createFromURL('');
const opts = await PDFNet.VerificationOptions.create(PDFNet.VerificationOptions.SecurityLevel.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. */
await opts.addTrustedCertificateUString(in_trusted_cert_path);
/* 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). */
await opts.enableOnlineCRLRevocationChecking(true);

const widgetAnnot = await PDFNet.SignatureWidget.createWithDigitalSignatureField(doc, new PDFNet.Rect(0, 100, 200, 150), doctimestamp_signature_field);
await (await doc.getPage(1)).annotPushBack(widgetAnnot);

// (OPTIONAL) Add an appearance to the signature field.
const img = await PDFNet.Image.createFromFile(doc, in_appearance_img_path);
await widgetAnnot.createSignatureAppearance(img);

console.log('Testing timestamping configuration.');
const config_result = await tst_config.testConfiguration(opts);
if (await config_result.getStatus()) {
  console.log('Success: timestamping configuration usable. Attempting to timestamp.');
} else {
  // Print details of timestamping failure.
  console.log(await config_result.getString());
  if (await config_result.hasResponseVerificationResult()) {
    const tst_result = await config_result.getResponseVerificationResult();
    console.log('CMS digest status: ' + await tst_result.getCMSDigestStatusAsString());
    console.log('Message digest status: ' + await tst_result.getMessageImprintDigestStatusAsString());
    console.log('Trust status: ' + await tst_result.getTrustStatusAsString());
  return false;

await doctimestamp_signature_field.timestampOnNextSave(tst_config, opts);

// Save/signing throws if timestamping fails.
await, PDFNet.SDFDoc.SaveOptions.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.