Generate QR Code in C# to Sign Documents and Images

QR Codes have gained popularity in recent years. As a developer, let us see how to programmatically generate QR codes in C# to electronically sign documents and images. In the earlier post, we discussed attaching QR codes with documents and images using Java.

Generate QR Codes in C# .NET to sign documents and images using GroupDocs.

The following topics will be converted in this article:

.NET API for QR Codes Generation

GroupDocs.Signature for .NET

In this article, I will be using GroupDocs.Signature for .NET API for generating QR codes. This API supports Aztec Code, DataMatrix Code, GS1 DataMatrix, GS1 QR, QR types. It also supports PDF files, word processing documents, spreadsheets, presentations, images, and a lot more document file formats to add QR codes.

For the examples below, I would recommend you to either install the API from the NuGet package manager or get the MSI installer, and DLLs from the downloads section. You may also use the following command in your Package Manager Console.

PM> Install-Package GroupDocs.Signature

For the details, you may visit the API Reference.

Generate QR Codes in C# – Add to PDF, Word, Excel, PPT files

The Signature and QrCodeSignOptions classes help to quickly create different types of QR codes and sign documents and images within .NET application. The following steps show how to generate QR codes using C# and then attach them to a PDF document:

  1. Initialize 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. (Aztec, DataMatrix, GS1 DataMatrix, GS1 QR, QR)
  4. Call the Sign method, passing the resultant document path and QR code options.

The following C# code implements the above steps. Similarly, you can provide a word document, spreadsheet, presentation, or any other supported document format to attach the generated QR codes.

This is the PDF file with QR code as an output of the above code.

Add generated QR Code to PDF using Signature API
PDF file with added QR code using GroupDocs.Signature for .NET API

Generate QR Codes in C# – Attach with JPG, PNG, or WebP Images

Add the generated QR code to Image.

You can use the same above code to attach the generated QR codes with the images as well. The API allows you to add QR codes to JPG/JPEG, PNG, WebP, BMP, GIF, SVG, CMX, and TIFF images and some more image file formats as well.

While generating QR codes, you can also change the background color, forecolor, transparency, and some more properties to alter their appearance. The below C#code changes the background color of the QR code to black and sets the forecolor to white.

Conclusion

I believe, now you are familiar with how to create QR codes in C# to sign your documents and images electronically within .NET applications. You can further change the appearance of the QR codes that suits your brand.

See Also