How to Sign PDF Document with QR Code in C#

This how-to guide explains the process to sign PDF document with QR Code in C#. We will also write a sample code to generate QR Code in C# by following the tutorial’s step-by-step instructions. Users can sign documents without the use of any third-party software. The detailed instructions and example for signing PDF documents using QR-Code signatures can be found below.

Steps to Sign PDF Document with QR Code in C#

  1. Setup GroupDocs.Signature for .NET package from NuGet.org website
  2. Add a reference to the necessary namespaces in the code
  3. Load the input PDF file by creating an instance of the Signature class
  4. Initialize QrCodeSignOptions class by creating an object of it
  5. Call the Sign method of the Signature class and pass the name of the output file along with signing options for the QR-Code

You can easily build the C# QR Code generator feature and use it to sign the PDF document by following the instructions above. Start by downloading the relevant package from the NuGet website and referencing the required namespaces in the code. Create an instance of the Signature class to load the source PDF file, and then initialize the QrCodeSignOptions class to set QR-Code signature options. Finally, sign the PDF document and save it to disc using the Sign method.

Code to Sign PDF Document with QR Code in C#

using System;
using GroupDocs.Signature;
using GroupDocs.Signature.Domain;
using GroupDocs.Signature.Options;
namespace SignPdfWithQRCodeInCSharp
{
class Program
{
public static void Main(string[] args) // Main function to eSign PDF with QR-Code using C#
{
// Remove the watermark in output PDF document by adding license
string licensePath = "GroupDocs.Signature.lic";
GroupDocs.Conversion.License lic = new GroupDocs.Conversion.License();
lic.SetLicense(licensePath);
// load the source PDF for eSign with QRCode
Signature signature = new Signature("sample.pdf");
// create QRCode option with predefined QRCode text
QrCodeSignOptions options = new QrCodeSignOptions("JohnSmith")
{
// setup QRCode encoding type
EncodeType = QrCodeTypes.QR,
// set signature position
Left = 50,
Top = 150,
Width = 200,
Height = 200
};
// sign document to file
SignResult result = signature.Sign("sign.pdf", options);
Console.WriteLine("Done");
}
}
}

We have utilized the aforementioned steps to develop the feature for PDF documents to eSign in C# in the example above. In this example, we have defined the left, top, width, and height of the QR-Code. However, you can customize the QR-Code by setting the signing options such as border, background color, text color, and font.

 English