Sign document with Digital signature - advanced
GroupDocs.Signature provides DigitalSignOptions class to specify different amount of settings for Digital signature
- digital certificate (file on local disk setCertificateFilePath or stream setCertificateStream) (required)
- password of digital certificate setPassword (required)
- digital signature details (setReason, setContact, setLocation)
- signature image as digital signature appearance on document page (setImageFilePath or setImageStream)
- image signature appearance on document page (setHorizontalAlignment, setMargin etc.)
Here are the steps to add Digital signature into document with GroupDocs.Signature:
- Create new instance of Signature class and pass source document path as a constructor parameter.
- Instantiate the DigitalSignOptions object with required certificate and its password.
- Call sign method of Signature class instance and pass DigitalSignOptions to it.
- Analyze SignResult result to check newly created signatures if needed.
This example shows how to sign PDF with Digital signature certificate and analyze SignResult
Signature signature = new Signature("sample.pdf");
DigitalSignOptions options = new DigitalSignOptions("certificate.pfx");
// certifiate password
options.setPassword("1234567890");
// digital certificate details
options.setReason("Sign");
options.setContact("JohnSmith");
options.setLocation("Office1");
// image as digital certificate appearance on document pages
options.setImageFilePath("sample.jpg");
//
options.setAllPages(true);
options.setWidth(80);
options.setHeight(60);
options.setVerticalAlignment(VerticalAlignment.Bottom);
options.setHorizontalAlignment(HorizontalAlignment.Right);
Padding padding = new Padding();
padding.setBottom(10);
padding.setRight(10);
options.setMargin(padding);
SignResult signResult = signature.sign("signed.pdf", options);
// analyzing result
System.out.print("List of newly created signatures:");
int number = 1;
for(BaseSignature temp : signResult.getSucceeded())
{
System.out.print("Signature #"+ number++ +": Type: "+temp.getSignatureType()+" Id:"+temp.getSignatureId()+
",Location: "+temp.getLeft()+"x"+temp.getTop()+". Size: "+temp.getWidth()+"x"+temp.getHeight());
}
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Signature for .NET examples, plugins, and showcase
- GroupDocs.Signature for Java examples, plugins, and showcase
- Document Signature for .NET MVC UI Example
- Document Signature for .NET App WebForms UI Example
- Document Signature for Java App Dropwizard UI Example
- Document Signature for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to eSign PDF, Word, Excel, PowerPoint documents with free to use online GroupDocs Signature App.