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 generating QR codes in Java to electronically sign your documents and images.

Add QR Code to documents and images in Java

Here are the quick links to the covered topics:

QR Code Generator - Java API

GroupDocs.Signature for Java

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

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

Download and Configure

You may get the JAR file from the downloads section, or add the following pom.xml configuration in your 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>21.2</version> 
</dependency>

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

The Signature and QrCodeSignOptions classes can quickly create and 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 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 generate QR code and attach it to the provided PDF document.

The resultant PDF file is shown here with the QR code that is added using the above code. Similarly, you can provide any word document, spreadsheet, presentation, or any other supported document format to attach the QR codes.

QR Code added to PDF using Signature API

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

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

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 generate QR code and add it 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.

Conclusion

Now, you should be confident enough to generate QR codes within your Java applications to electronically signing documents and images using GroupDocs.Signature. To remove any ambiguity or any unaddressed scenario on the documentation, feel free to contact the Support Team on the forum. Many other examples are also available on GitHub.

See Also