Some test text!


Add a DocTimeStamp signature on iOS

To add a DocTimeStamp signature:

PTPDFDoc* doc = [[PTPDFDoc alloc] initWithFilepath: in_docpath];
PTDigitalSignatureField* doctimestamp_signature_field = [doc CreateDigitalSignatureField: @""];
PTTimestampingConfiguration* tst_config = [[PTTimestampingConfiguration alloc] initWithIn_url: @""];
PTVerificationOptions* opts = [[PTVerificationOptions alloc] initWithLevel:e_ptcompatibility_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. */
[ opts AddTrustedCertificateWithFilePath: 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). */
[ opts EnableOnlineCRLRevocationChecking: YES];

PTSignatureWidget* widgetAnnot = [PTSignatureWidget CreateWithDigitalSignatureField: doc pos: [[PTPDFRect alloc] initWithX1: 0 y1: 100 x2: 200 y2: 150] field: doctimestamp_signature_field];
[[doc GetPage: 1] AnnotPushBack: widgetAnnot];

// (OPTIONAL) Add an appearance to the signature field.
PTImage* img = [PTImage CreateWithFile: [doc GetSDFDoc] filename: in_appearance_img_path encoder_hints: [[PTObj alloc]init]];

[widgetAnnot CreateSignatureAppearance: img];

NSLog(@"Testing timestamping configuration.");
PTTimestampingTestResult* config_result = [tst_config TestConfiguration:opts];
if([ config_result GetStatus])
    NSLog(@"Success: timestamping configuration usable. Attempting to timestamp.");
    // Print details of timestamping failure.
    NSLog(@"%@", [config_result GetString]);
    if ([config_result HasResponseVerificationResult])
        PTEmbeddedTimestampVerificationResult* tst_result = [config_result GetResponseVerificationResult];
        NSLog(@"CMS digest status: %@\n", [tst_result GetCMSDigestStatusAsString]);
        NSLog(@"Message digest status: %@\n", [tst_result GetMessageImprintDigestStatusAsString]);
        NSLog(@"Trust status: %@\n", [tst_result GetTrustStatusAsString]);
    return NO;

[doctimestamp_signature_field TimestampOnNextSave: tst_config in_timestamp_response_verification_options: opts];

// Save/signing throws if timestamping fails.
[doc SaveToFile: in_outpath flags: e_ptincremental];

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.