Right PDF SDK provides APIs to sign PDF documents with digital signatures and protect document content from unauthorized changes. Functions include creating a digital signature, removing an existing digital signature, cleaning signature data, setting signature appearance and properties of a digital signature, and verifying the validity of a signature. Here are some common APIs for signature operations listed in Table 3.13. For a complete list of APIs, please refer to ZSSignature.h.


Table 3.13

  API Name Description
1 ZSSignature_Add Add an unsigned signature field to a specific position on a PDF page.
2 ZSSignature_Remove Remove a signature.
3 ZSDoc_NumSignatures Get signature count in a PDF document.
4 ZSSignature_GetDoc Retrieve the PDF document related to a specific signature.
5 ZSSignature_ResetAppearance Reset the appearance of a signature field.
6 ZSSignature_SetFilter Set the name of the preferred signature handler to use for signature.
7 ZSSignature_InitValue Create a signature field.
8 ZSSignature_SetLocation Get location information of a signature owner.
9 ZSSignature_GetDateTime Get the creation time of a signature.
10 ZSSignature_StartVerify Verify a signature using a specified filter.
11 ZSSignature_SetImage Set an image to display in a signature field.
12 ZSSignature_StartSign Sign a PDF document progressively using a specified filter.
13 ZSSignature_GetSigner Get the signer’s name of a signature.
14 ZSSignature_ClearData Clear signature data and its appearance.

 


This is an example of how to sign a PDF document with a certificate.

Example: Sign the PDF document with a signature.

ZS_BSTRC(filename, “./inputFile.pdf”);
ZSDoc doc;
ZSDoc_Open(&filename, NULL, &doc);
ZSPage page;
ZSDoc_AcquirePage(doc, 0, &page);
ZSForm form;
ZSDoc_CreateForm(doc, &form);

ZSFRect rect = {0, 100, 100, 0};
ZSSignature sig;
ZSSignature_Add(page, &rect, &sig);
ZSSignature_InitValue(sig);
ZSSignature_SetDefaultContentsLength(sig, 8196);

ZS_BSTRC(filter, “Adobe.PPKLite”);
ZSSignature_SetFilter(sig, &filter);
ZS_BSTRC(subFilter, “adbe.pkcs7.detached”);
ZSSignature_SetSubFilter(sig, &subFilter);

ZS_BSTRC(certFile, “./cert.pfx”);
ZS_BSTRC(password, “123456”);
ZSSignature_Certificate_AddPFX(sig, &certFile, &password);
ZSSignature_ResetAppearance(sig);

ZSBSTr_InitConstString(filename, “./outputFile,pdf”);
ZSSignature_StartSign(sig, &filename, NULL);

ZSSignature_ClearDate(sig);
ZSPage_Release(page);
ZSForm_Release(form);
ZSDoc_Close(doc);