To sign an existing approval signature field in a PDF Document:
1using (PDFDoc doc = new PDFDoc(docpath))
2{
3 // Retrieve the unsigned approval signature field.
4 Field found_approval_field = doc.GetField(approval_field_name);
5 DigitalSignatureField approval_digsig_field = new DigitalSignatureField(found_approval_field);
6
7 // (OPTIONAL) Add more information to the signature dictionary.
8 approval_digsig_field.SetLocation("Vancouver, BC");
9 approval_digsig_field.SetReason("Document approval.");
10 approval_digsig_field.SetContactInfo("www.apryse.com");
11
12 // (OPTIONAL) Add an appearance to the signature field.
13 Image img = Image.Create(doc, appearance_img_path);
14 SignatureWidget approval_signature_widget = new SignatureWidget(found_approval_field.GetSDFObj());
15 approval_signature_widget.CreateSignatureAppearance(img);
16
17 // Prepare the signature and signature handler for signing.
18 approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);
19
20 // The actual approval signing will be done during the following incremental save operation.
21 doc.Save(outpath, SDFDoc.SaveOptions.e_incremental);
22}
1PDFDoc doc(docpath);
2
3// Retrieve the unsigned approval signature field.
4Field found_approval_field(doc.GetField(approval_field_name));
5PDF::DigitalSignatureField approval_digsig_field(found_approval_field);
6
7// (OPTIONAL) Add more information to the signature dictionary.
8approval_digsig_field.SetLocation("Vancouver, BC");
9approval_digsig_field.SetReason("Document approval.");
10approval_digsig_field.SetContactInfo("www.apryse.com");
11
12// (OPTIONAL) Add an appearance to the signature field.
13PDF::Image img = PDF::Image::Create(doc, appearance_img_path);
14Annots::SignatureWidget approval_signature_widget(found_approval_field.GetSDFObj());
15approval_signature_widget.CreateSignatureAppearance(img);
16
17// Prepare the signature and signature handler for signing.
18approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);
19
20// The actual approval signing will be done during the following incremental save operation.
21doc.Save(outpath, SDFDoc::e_incremental, NULL);
1doc := NewPDFDoc(docpath)
2
3// Retrieve the unsigned approval signature field.
4foundApprovalField := doc.GetField(inApprovalFieldName)
5foundApprovalSignatureDigsigField := NewDigitalSignatureField(foundApprovalField)
6
7// (OPTIONAL) Add more information to the signature dictionary.
8foundApprovalSignatureDigsigField.SetLocation("Vancouver, BC")
9foundApprovalSignatureDigsigField.SetReason("Document approval.")
10foundApprovalSignatureDigsigField.SetContactInfo("www.apryse.com")
11
12// (OPTIONAL) Add an appearance to the signature field.
13img := ImageCreate(doc.GetSDFDoc(), inAppearanceImgPath)
14foundApprovalSignatureWidget := NewSignatureWidget(foundApprovalField.GetSDFObj())
15foundApprovalSignatureWidget.CreateSignatureAppearance(img)
16
17// Prepare the signature and signature handler for signing.
18foundApprovalSignatureDigsigField.SignOnNextSave(inPrivateKeyFilePath, inKeyfilePassword)
19
20// The actual approval signing will be done during the following incremental save operation.
21doc.Save(inOutpath, uint(SDFDocE_incremental))
1PDFDoc doc = new PDFDoc(docpath);
2
3// Retrieve the unsigned approval signature field.
4Field found_approval_field = doc.getField(approval_field_name);
5DigitalSignatureField approval_digsig_field = new DigitalSignatureField(found_approval_field);
6
7// (OPTIONAL) Add more information to the signature dictionary.
8approval_digsig_field.setLocation("Vancouver, BC");
9approval_digsig_field.setReason("Document approval.");
10approval_digsig_field.setContactInfo("www.apryse.com");
11
12// (OPTIONAL) Add an appearance to the signature field.
13Image img = Image.create(doc, appearance_img_path);
14SignatureWidget approval_signature_widget = new SignatureWidget(found_approval_field.getSDFObj());
15approval_signature_widget.createSignatureAppearance(img);
16
17// Prepare the signature and signature handler for signing.
18approval_digsig_field.signOnNextSave(private_key_file_path, keyfile_password);
19
20// The actual approval signing will be done during the following incremental save operation.
21doc.save(outpath, SDFDoc.SaveMode.INCREMENTAL, null);
1async function main() {
2 const doc = await PDFNet.PDFDoc.createFromFilePath(in_docpath);
3
4 // Retrieve the unsigned approval signature field.
5 const found_approval_field = await doc.getField(in_approval_field_name);
6 const found_approval_signature_digsig_field = await PDFNet.DigitalSignatureField.createFromField(found_approval_field);
7
8 // (OPTIONAL) Add more information to the signature dictionary.
9 await found_approval_signature_digsig_field.setLocation('Vancouver, BC');
10 await found_approval_signature_digsig_field.setReason('Document certification.');
11 await found_approval_signature_digsig_field.setContactInfo('www.apryse.com');
12
13 // (OPTIONAL) Add an appearance to the signature field.
14 const img = await PDFNet.Image.createFromFile(doc, in_appearance_img_path);
15 const found_approval_signature_widget = await PDFNet.SignatureWidget.createFromObj(await found_approval_field.getSDFObj());
16 await found_approval_signature_widget.createSignatureAppearance(img);
17
18 // Prepare the signature and signature handler for signing.
19 await found_approval_signature_digsig_field.signOnNextSave(in_private_key_file_path, in_keyfile_password);
20
21 // The actual approval signing will be done during the following incremental save operation.
22 await doc.save(in_outpath, PDFNet.SDFDoc.SaveOptions.e_incremental);
23}
24PDFNet.runWithCleanup(main);
1PTPDFDoc* doc = [[PTPDFDoc alloc] initWithFilepath: docpath];
2
3// Retrieve the unsigned approval signature field.
4PTField* found_approval_field = [doc GetField: approval_field_name];
5PTDigitalSignatureField* approval_digsig_field = [[PTDigitalSignatureField alloc] initWithIn_field: found_approval_field];
6
7// (OPTIONAL) Add more information to the signature dictionary.
8[approval_digsig_field SetLocation: @"Vancouver, BC"];
9[approval_digsig_field SetReason: @"Document approval."];
10[approval_digsig_field SetContactInfo: @"www.apryse.com"];
11
12// (OPTIONAL) Add an appearance to the signature field.
13PTImage* img = [PTImage CreateWithFile: [doc GetSDFDoc] filename: appearance_img_path encoder_hints: [[PTObj alloc]init]];
14PTSignatureWidget* approval_signature_widget = [[PTSignatureWidget alloc] initWithD: [found_approval_field GetSDFObj]];
15[approval_signature_widget CreateSignatureAppearance: img];
16
17// Prepare the signature and signature handler for signing.
18[approval_digsig_field SignOnNextSave: private_key_file_path in_password: keyfile_password];
19
20// The actual approval signing will be done during the following incremental save operation.
21[doc SaveToFile: outpath flags: e_ptincremental];
1$doc = new PDFDoc($docpath);
2
3// Retrieve the unsigned approval signature field.
4$found_approval_field = $doc->GetField($approval_field_name);
5$approval_digsig_field = new DigitalSignatureField($found_approval_field);
6
7// (OPTIONAL) Add more information to the signature dictionary.
8$approval_digsig_field->SetLocation('Vancouver, BC');
9$approval_digsig_field->SetReason('Document approval.');
10$approval_digsig_field->SetContactInfo('www.apryse.com');
11
12// (OPTIONAL) Add an appearance to the signature field.
13$img = Image::Create($doc->GetSDFDoc(), $appearance_img_path);
14$found_approval_signature_widget = new SignatureWidget($found_approval_field->GetSDFObj());
15$found_approval_signature_widget->CreateSignatureAppearance($img);
16
17// Prepare the signature and signature handler for signing.
18$approval_digsig_field->SignOnNextSave($private_key_file_path, $keyfile_password);
19
20// The actual approval signing will be done during the following incremental save operation.
21$doc->Save($outpath, SDFDoc::e_incremental);
1doc = PDFDoc(docpath)
2
3# Retrieve the unsigned approval signature field.
4found_approval_field = doc.GetField(approval_field_name)
5approval_digsig_field = DigitalSignatureField(found_approval_field)
6
7# (OPTIONAL) Add more information to the signature dictionary.
8approval_digsig_field.SetLocation('Vancouver, BC')
9approval_digsig_field.SetReason('Document approval.')
10approval_digsig_field.SetContactInfo('www.apryse.com')
11
12# (OPTIONAL) Add an appearance to the signature field.
13img = Image.Create(doc.GetSDFDoc(), appearance_img_path)
14found_approval_signature_widget = SignatureWidget(found_approval_field.GetSDFObj())
15found_approval_signature_widget.CreateSignatureAppearance(img)
16
17# Prepare the signature and signature handler for signing.
18approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password)
19
20# The actual approval signing will be done during the following incremental save operation.
21doc.Save(outpath, SDFDoc.e_incremental)
1doc = PDFDoc.new(docpath);
2
3# Retrieve the unsigned approval signature field.
4found_approval_field = doc.GetField(approval_field_name);
5approval_digsig_field = DigitalSignatureField.new(found_approval_field);
6
7# (OPTIONAL) Add more information to the signature dictionary.
8approval_digsig_field.SetLocation('Vancouver, BC');
9approval_digsig_field.SetReason('Document approval.');
10approval_digsig_field.SetContactInfo('www.apryse.com');
11
12# (OPTIONAL) Add an appearance to the signature field.
13img = Image.Create(doc.GetSDFDoc, appearance_img_path);
14found_approval_signature_widget = SignatureWidget.new(found_approval_field.GetSDFObj());
15found_approval_signature_widget.CreateSignatureAppearance(img);
16
17# Prepare the signature and signature handler for signing.
18approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password);
19
20# The actual approval signing will be done during the following incremental save operation.
21doc.Save(outpath, SDFDoc::E_incremental);
1Using doc As PDFDoc = New PDFDoc(docpath)
2 ' Retrieve the unsigned approval signature field.
3 Dim found_approval_field As Field = doc.GetField(approval_field_name)
4 Dim approval_digsig_field As DigitalSignatureField = New DigitalSignatureField(found_approval_field)
5 Dim img As Image = Image.Create(doc, appearance_img_path)
6
7 ' (OPTIONAL) Add more information to the signature dictionary.
8 approval_digsig_field.SetLocation("Vancouver, BC")
9 approval_digsig_field.SetReason("Document approval.")
10 approval_digsig_field.SetContactInfo("www.apryse.com")
11
12 ' (OPTIONAL) Add an appearance to the signature field.
13 Dim found_approval_signature_widget As SignatureWidget = New SignatureWidget(found_approval_field.GetSDFObj())
14 found_approval_signature_widget.CreateSignatureAppearance(img)
15
16 ' Prepare the signature and signature handler for signing.
17 approval_digsig_field.SignOnNextSave(private_key_file_path, keyfile_password)
18
19 ' The actual approval signing will be done during the following incremental save operation.
20 doc.Save(in_outpath, SDFDoc.SaveOptions.e_incremental)
21End Using
Digitally sign PDF files
Full code sample which demonstrates using the digital signature API to digitally sign and/or certify PDF documents.
The Apryse SDK enables approval signatures in PDF documents using a Digital Certificate, in accordance with the latest PDF specification. By leveraging public key infrastructure (PKI) technology, with a certificate issued by a trusted certificate authority (CA), a signer can use a certificate-based digital ID to guarantee the authenticity of a signature. Placement of a digital signature using a certificate can also guarantee that a document was not modified since the signature was placed, ensuring the authenticity of the document.
Image taken from Apryse WebViewer
Above is an example of a document containing a certified signature, guaranteed by a certificate generated by Apryse.com.
Did you find this helpful?
Trial setup questions?
Ask experts on DiscordNeed other help?
Contact SupportPricing or product questions?
Contact Sales