Sign and verify documents with GroupDocs.Signature

GroupDocs.Signature applies electronic signatures to a document and finds them again afterwards. It supports text, image, digital certificate, barcode, QR-code, stamp, metadata and form-field signature types across Word, PDF, Excel, PowerPoint and image formats.

The three examples below cover the full lifecycle: sign, sign again, search.

Sign a document with a text signature

A text signature draws text onto the page at a position you choose. setLeft/setTop place it, setWidth/setHeight bound it.

import com.groupdocs.signature.Signature;
import com.groupdocs.signature.options.sign.TextSignOptions;

Signature signature = new Signature("contract.docx");

TextSignOptions signOptions = new TextSignOptions("John Smith");
signOptions.setLeft(100);
signOptions.setTop(100);
signOptions.setWidth(200);
signOptions.setHeight(40);

signature.sign("signature-sign-with-text.docx", signOptions);

contract.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 16 KB)

Download full output

Sign a document with a QR code

A QR-code signature encodes arbitrary text — an approval id, a verification URL — into a scannable code placed on the page. Set setEncodeType to the encoding you want; QrCodeTypes.QR is the standard one.

import com.groupdocs.signature.Signature;
import com.groupdocs.signature.domain.qrcodes.QrCodeTypes;
import com.groupdocs.signature.options.sign.QrCodeSignOptions;

Signature signature = new Signature("contract.docx");

QrCodeSignOptions signOptions = new QrCodeSignOptions("Approved by John Smith");
signOptions.setEncodeType(QrCodeTypes.QR);
signOptions.setLeft(100);
signOptions.setTop(100);
signOptions.setWidth(120);
signOptions.setHeight(120);

signature.sign("signature-sign-with-qr-code.docx", signOptions);

contract.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 20 KB)

Download full output

Search a document for signatures

Searching answers “what is on this document?”. It returns every signature of the type you ask for, with its text and encoding.

import com.groupdocs.signature.Signature;
import com.groupdocs.signature.domain.qrcodes.QrCodeTypes;
import com.groupdocs.signature.domain.signatures.QrCodeSignature;
import com.groupdocs.signature.options.search.QrCodeSearchOptions;
import com.groupdocs.signature.options.sign.QrCodeSignOptions;
import java.util.List;

// Sign first, so there is something to find
Signature signature = new Signature("contract.docx");
QrCodeSignOptions signOptions = new QrCodeSignOptions("Approved by John Smith");
signOptions.setEncodeType(QrCodeTypes.QR);
signOptions.setLeft(100);
signOptions.setTop(100);
signature.sign("signature-search.docx", signOptions);

// Now search the signed document
Signature searcher = new Signature("signature-search.docx");
QrCodeSearchOptions searchOptions = new QrCodeSearchOptions();
List<QrCodeSignature> signatures = searcher.search(QrCodeSignature.class, searchOptions);

System.out.println("Signatures found: " + signatures.size());

for (QrCodeSignature qrSignature : signatures) {
    System.out.println("Text: " + qrSignature.getText());
}

contract.docx is the sample file used in this example. Click here to download it.

Binary file (DOCX, 20 KB)

Download full output

Learn more

GroupDocs.Signature also applies digital certificate signatures, image and stamp signatures, metadata and form-field signatures; verifies a document against expected signature values; and updates or deletes signatures already present.

Close
Loading

Analyzing your prompt, please hold on...

An error occurred while retrieving the results. Please refresh the page and try again.