Signatures
Foxit PDF SDK for Android provides digital signature creation, verification, removal, and property management through the Core SDK. Digital signatures let recipients verify document origin and whether content was altered.
Built-in signing in UI Extensions
If you use the full reader (UI Extensions), the digital signature module (DigitalSignatureModule), handwriting signature module (SignatureModule), and signature panel (SignaturePanelModule) for viewing and verifying signatures are built in. No extra code is required.
Default supported signature types
The SDK includes default signature callbacks for these filter/subfilter pairs without a custom callback:
Adobe.PPKLite+adbe.pkcs7.detachedAdobe.PPKLite+adbe.pkcs7.sha1
Core Classes
| Class | Description |
|---|---|
Signature | Signature object; create, sign, verify, and manage properties. Created with PDFPage.addSignature(), retrieved with PDFDoc.getSignature() |
Signature Key Constants
Set signature info with setKeyValue(int key, String value):
| Constant | Value | Description |
|---|---|---|
e_KeyNameSigner | 0 | Signer |
e_KeyNameLocation | 1 | Location |
e_KeyNameReason | 2 | Reason |
e_KeyNameContactInfo | 3 | Contact info |
e_KeyNameDN | 4 | Distinguished name |
e_KeyNameText | 5 | Custom text |
Appearance Flag Constants
Control appearance content with setAppearanceFlags(int flags):
| Constant | Value | Description |
|---|---|---|
e_APFlagLabel | 0x0002 | Show label |
e_APFlagReason | 0x0004 | Show reason |
e_APFlagSigningTime | 0x0008 | Show signing time |
e_APFlagDN | 0x0010 | Show DN |
e_APFlagLocation | 0x0020 | Show location |
e_APFlagSigner | 0x0040 | Show signer |
e_APFlagBitmap | 0x0080 | Show image |
e_APFlagText | 0x0100 | Show custom text |
Digest Algorithm Constants
| Constant | Value | Description |
|---|---|---|
e_DigestSHA1 | 0 | SHA-1 |
e_DigestSHA256 | 1 | SHA-256 |
e_DigestSHA384 | 2 | SHA-384 |
e_DigestSHA512 | 3 | SHA-512 |
Common Verification State Constants
After verification, use getState() with bitwise AND:
| Constant | Description |
|---|---|
e_StateUnsigned | Not signed |
e_StateSigned | Signed |
e_StateVerifyValid | Signature valid |
e_StateVerifyInvalid | Signature invalid |
e_StateVerifyChange | Document modified |
e_StateVerifyNoChange | Document not modified |
e_StateVerifyIssueValid | Issuer certificate valid |
e_StateVerifyIssueExpire | Issuer certificate expired |
Example: Sign and Verify
java
import com.foxit.sdk.pdf.PDFDoc;
import com.foxit.sdk.pdf.PDFPage;
import com.foxit.sdk.pdf.Signature;
import com.foxit.sdk.common.Progressive;
import com.foxit.sdk.common.fxcrt.RectF;
PDFDoc doc = new PDFDoc("path/to/Sample.pdf");
doc.load(null);
PDFPage page = doc.getPage(0);
// Add signature field
Signature signature = page.addSignature(new RectF(100, 600, 300, 700));
// Set appearance
signature.setAppearanceFlags(
Signature.e_APFlagLabel | Signature.e_APFlagDN |
Signature.e_APFlagReason | Signature.e_APFlagSigner |
Signature.e_APFlagSigningTime | Signature.e_APFlagLocation
);
// Set signature info
signature.setKeyValue(Signature.e_KeyNameSigner, "张三");
signature.setKeyValue(Signature.e_KeyNameLocation, "北京");
signature.setKeyValue(Signature.e_KeyNameReason, "文档审批");
signature.setFilter("Adobe.PPKLite");
signature.setSubFilter("adbe.pkcs7.detached");
// Sign
Progressive progressive = signature.startSign(
"/sdcard/cert.pfx", "123".getBytes(),
Signature.e_DigestSHA256, "/sdcard/signed.pdf", null, null);
int state = Progressive.e_ToBeContinued;
while (state == Progressive.e_ToBeContinued) {
state = progressive.resume();
}
// Verify all signatures in signed document
PDFDoc signedDoc = new PDFDoc("/sdcard/signed.pdf");
signedDoc.load(null);
int count = signedDoc.getSignatureCount();
for (int i = 0; i < count; i++) {
Signature sig = signedDoc.getSignature(i);
if (sig == null || sig.isEmpty()) continue;
Progressive verifyProgress = sig.startVerify(null, null);
int vState = Progressive.e_ToBeContinued;
while (vState == Progressive.e_ToBeContinued) {
vState = verifyProgress.resume();
}
int verifiedState = sig.getState();
if ((verifiedState & Signature.e_StateVerifyValid) != 0) {
// Signature valid
}
}Example: Custom Signing Time
setSignTime does not support arbitrary time formats directly. To set a custom time string, write it to the signature dictionary:
java
Signature signature = page.addSignature(rect);
signature.setAppearanceFlags(Signature.e_APFlagSigningTime | Signature.e_APFlagSigner);
PDFDictionary dict = signature.getSignatureDict();
dict.setAtString("M", "2025/01/14 10:30:00");API Reference
See the API Reference for full Signature documentation.