We are back with a major update for our customers who are using the eSign API - GroupDocs.Signature for Java. We have performed major product optimization and revamped the architecture which has made the API more memory efficient and easy to use. We have also added the support of a couple of new file formats. Let’s have an overview of this amazing release and check out what you would get after upgrading to API v2.

What is New in API v2?

We have simplified the way of signing the documents as well as improved the working of the API. Have a look at the key reasons why you should upgrade to the latest release.

  • The previous versions of the API had separate classes to deal with each supported document format. For example, we had PdfSignTextOptions class for text signatures in PDF files and WordsSignTextOptions class for Word Processing documents. But now, we have introduced a unified approach where the signature, verification, and search options are related to signature types only and not the document formats. A single class, TextSignOptions will now be used for all the document formats.

  • The Signature class is introduced as a single entry point to sign the document with various signature types as well as perform verification and search.

  • The overall document related classes that were used to deal with different document formats have been unified to common classes.

  • The API’s architecture is redesigned from scratch in order to simplify the usage of options and classes to manipulate all the signature types.

  • The procedures of getting the document’s information and generating the previews for the documents are also simplified.

How to Migrate?

The migration process is not as complex as it is supposed to be for the API versions with major updates. The legacy API has been moved into the com.groupdocs.signature.legacy package. Once you upgrade, it is required to make a project-wide replacement of imports from com.groupdocs.signature. to com.groupdocs.signature.legacy to resolve build issues.

The following is a code comparison of the previous versions with the latest one. It will give you an overview of how the coding style, the classes, and the methods have been changed.

Signing Document with Text Signature

Old Versions

// setup configuration
SignatureConfig signConfig =new SignatureConfig();
signConfig.setStoragePath("C:\\Storage");
signConfig.setOutputPath("C:\\Output");
// instantiate the conversion handler
SignatureHandler<String> handler = new SignatureHandler<String>(signConfig);
// setup text signature options
PdfSignTextOptions signOptions = new PdfSignTextOptions("John Smith");
// setup colors settings
signOptions.setBackgroundColor(Color.BLUE);
// setup text color
signOptions.setForeColor(Color.RED);
// setup Font options
signOptions.getFont().setBold(true);
signOptions.getFont().setItalic(true);
signOptions.getFont().setUnderline(true);
signOptions.getFont().setStrikeout(true);
signOptions.getFont().setFontFamily("Arial");
signOptions.getFont().setFontSize(15);
// sign document
SaveOptions saveOptions = new SaveOptions();
saveOptions.setOutputType(OutputType.String);
saveOptions.setOutputFileName("Pdf_TextSignatureFontBackgroundAndColorOptions");
String signedPath = handler.<String>sign("test.pdf", signOptions, saveOptions);

Version 19.11 or Later

Signature signature = new Signature("sample.pdf");
// Set signature text and appearance
TextSignOptions options = new TextSignOptions("John Smith");
// set signature position
options.setLeft(100);
options.setTop(100);
// set signature rectangle
options.setWidth(100);
options.setHeight(30);
// set text color and Font
options.setForeColor(Color.RED);
SignatureFont signatureFont = new SignatureFont();
signatureFont.setSize(12);
signatureFont.setFamilyName("Comic Sans MS");
options.setFont(signatureFont);
// sign document to file
signature.sign("signed.pdf", options);

Setting Up Encryption for Metadata Signature

In addition to the major update, we have also added the feature of setting up the encryption for the metadata signature at the options levels. The MetadataSignOptions class provides setDataEncryption method to specify the encryption type (read more). The following code sample shows how to use this option:

Signature signature = new Signature("sample.docx");
// setup key and passphrase
String key = "1234567890";
String salt = "1234567890";
// create data encryption
IDataEncryption encryption = new SymmetricEncryption(SymmetricAlgorithmType.Rijndael, key, salt);
// setup options with text of signature
MetadataSignOptions options = new MetadataSignOptions();
// set encryption for all metadata signatures for this options
// if you need separate encryption use own MetadataSignature.DataEncryption property
options.setDataEncryption(encryption);
// setup signature metadata
WordProcessingMetadataSignature mdAuthor = new WordProcessingMetadataSignature("Author", "Mr.Scherlock Holmes");
// setup data of document id
WordProcessingMetadataSignature mdDocId = new WordProcessingMetadataSignature("DocumentId", java.util.UUID.randomUUID().toString());
// add signatures to options
options.getSignatures().add(mdAuthor);
options.getSignatures().add(mdDocId);
// sign document to file
signature.sign("MetadataEncryptedText.docx", options);

Support of New File Formats

We have added the support of following file formats in the latest release:

If you are interested in migration to the latest release, just download and integrate v19.11 in your applications. We have also updated the source code examples in our GitHub repository so you can easily evaluate the API v2. For more details, consult the documentation or have a conversation with us on our forum.