eSign Documents and Images with QR Code in Java

QR code (Quick Response code) is the type of 2D Barcodes or matrix barcode. It is the machine-readable label that contains information about the attached item. This article will guide you about programmatically adding QR codes to electronically sign your documents and images using Java.

Add QR Code to documents and images in Java

Here are the quick links to the covered topics:

Java API for QR Codes

GroupDocs.Signature for Java

In this article, I am using GroupDocs.Signature for Java API to add QR codes in PDF files, word documents, spreadsheets, presentations, and images. This API supports different types of electronic signatures for a vast variety of file formats. From the QR code types, the API supports the following:

  • Aztec Code
  • DataMatrix Code
  • GS1 DataMatrix
  • GS1 QR
  • QR

You may get the JAR file from the downloads section, or add the following pom.xml configuration in Maven-based Java applications before you move on to examples. For the details, you may visit the API Reference.

<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>

Add QR Code to PDF, Word, Excel, PPT in Java

The Signature and QrCodeSignOptions classes can quickly add different types of QR codes to documents and images in Java.

  1. Create the Signature class object with the source document.
  2. Set the QR code properties using the QrCodeSignOptions class.
  3. Most importantly, select the appropriate from the available QR code types.
  4. Call the sign method with the Signature object, passing the resultant document path and QR code options.

The following Java code will add a QR code to the provided PDF document. Similarly, you can provide any word document, spreadsheet, presentation, or any other supported document format to attach the QR codes.

The resultant PDF file is shown here with the QR code that is added using the above code.

QR Code added to PDF using Signature API
PDF file with added QR code using GroupDocs.Signature for Java API

Add QR Code to JPG, PNG, or WebP Images in Java

Image with QR Code

Now, you might be thinking that there will be a different strategy to add QR codes to images. The answer is NO. You can use the same above code to add a QR code to the images as well. The API allows you to add QR codes to JPG/JPEG, PNG, WebP, BMP, GIF, SVG, CMX, and TIFF images.

You can also change the appearance of the QR codes like background color, forecolor, transparency, and more. Here, I have set the black background color and forecolor as white.

// Change Appearance of QR code.
// Setting background color, forecolor, transparency, etc.)
Background background = new Background();
background.setColor(Color.BLACK);
background.setTransparency(0.5);

options.setBackground(background);
options.setForeColor(Color.WHITE);

Conclusion

Now, you should be confident enough to easily add QR codes for electronically signing documents and images using GroupDocs.Signature in your Java applications. To clear any ambiguity or any unaddressed scenario, feel free to contact Free Support Team on the forum.

See Also