Sign Documents with Digital Signatures using Java

A digital signature is a mathematical technique to verify the document’s authenticity. For documents, the digital signature is represented by certificate with private and public keys. As a Java developer, you can easily sign your documents with digital certificates programmatically. This article will be focusing on how to electronically sign documents with digital signatures using Java.

The following topics are discussed/covered in this article:

Java API for Signing Documents

I will be using GroupDocs.Signature for Java API for signing documents with the digital certificate. It helps you develop Java applications to electronically sign digital documents of supported formats. It also allows signing images and documents with Image, QR-Code, Barcode, Metadata, Text & Stamp Type electronic signatures.

Download and Configure

You can download the JAR of the API or just add the following pom.xml configuration in your Maven-based Java applications to try the below-mentioned code examples.

<repository>
	<id>GroupDocsJavaAPI</id>
	<name>GroupDocs Java API</name>
	<url>http://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
        <groupId>com.groupdocs</groupId>
        <artifactId>groupdocs-signature</artifactId>
        <version>20.9</version> 
</dependency>

Sign PDF Documents with Digital Signatures using Java

You can electronically sign your PDF documents with digital signatures by following the simple steps mentioned below:

  • Create an instance of the Signature class
  • Provide path of the PDF document
  • Create an instance of the DigitalSignOptions class
  • Provide the certificate file path
  • Set the image file path
  • Set required sign options such as position (Top, Left etc.)
  • Then call the Sign method to sign the document

The following code sample shows how to sign the PDF documents with the certificate using Java.

Sign PDF Document with Digital Certificate using Java
Sign PDF Document with Digital Certificate using Java

The Signature class is the main class that controls the document signing process. This class provides various methods to sign, verify, update and search signatures.

The DigitalSignOptions class provides various methods to set and get sign options to represent digital signatures.

Sign Word Documents with Digital Signatures using Java

You can electronically sign your Word documents with digital signatures by following the simple steps mentioned below:

  • Create an instance of the Signature class
  • Provide path of the Word file
  • Create an instance of the DigitalSignOptions class
  • Provide the certificate file path
  • Set the image file path
  • Set required sign options such as position (Top, Left etc.)
  • Then call the Sign method to sign the document

The following code sample shows how to sign the DOCX file with the certificate using Java.

Sign Word documents with digital certificates using Java
Sign Word documents with digital certificates using Java

Get a Free License

You can try the API without evaluation limitations by requesting a free temporary license.

Conclusion

In this article, you have learned how to electronically sign documents with digital signatures using Java. You can learn more about GroupDocs.Signature for Java API using the documentation. In case of any ambiguity, please feel free to contact us on the forum.

See Also