Generate QR Code to Sign PDF using REST API in PHP.

A QR Code, short for “Quick Response code,” is a pattern of black and white squares that can be read by machines. It serves as an optical label containing information that can be read by a QR reader. In this article, we’ll explore how to create QR codes programmatically and use them to digitally sign PDF documents using a REST API in PHP.

The following topics shall be covered in this article:

QR Code Generator REST API and PHP SDK

For generating QR codes to sign PDF documents, we will be using the PHP SDK of GroupDocs.Signature Cloud API. It allows creating, verifying, and searching various types of signatures such as image, ‎barcode, QR-Code, text-based, digital, and stamp signatures. It supports the following QR code types:

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

Please install it using the following command in the console:

composer require groupdocscloud/groupdocs-signature-cloud

After installation, please use the Composers’ autoload to use the SDK as shown below:

require_once('vendor/autoload.php');

Please get your Client ID and Secret from the dashboard before following the mentioned steps. Once you have your ID and secret, add in the code as shown below:

Generate QR Code to Sign PDF using REST API in PHP

We can generate the QR code to sign the PDF documents on the cloud by following the simple steps mentioned below:

Upload the Document

Firstly, we will upload the PDF document to the cloud using the code sample given below:

As a result, the uploaded PDF file will be available in the files section of the dashboard on the cloud.

Generate QR Code to Sign PDF in PHP

We can generate QR code programmatically and sign the uploaded PDF document by following the steps given below:

  1. Firstly, create an instance of the SignApi.
  2. Next, provide the input PDF file path.
  3. Then, set the output file path.
  4. Next, initialize the SignQRCodeOptions object.
  5. Then, set the QRCodeType to “QR”. Moreover, set the text, and its position.
  6. Optionally, set options such as Page, RotationAngle, HorizontalAlignment, Border, Padding etc.
  7. After that, create the createSignaturesRequest with the defined SignSettings.
  8. Finally, get results by calling the createSignatures() method.

The following code sample shows how to generate a QR code and sign the PDF document using a REST API in PHP.

Generate QR Code to Sign PDF using REST API in PHP.

Generate QR Code to Sign PDF using REST API in PHP.

Download the PDF Signed with QR Code

The above code sample will save the signed PDF file on the cloud. It can be downloaded using the following code sample:

Generate Aztec Code to Sign PDF in PHP

The Aztec code is the most easy-to-print and easy-to-scan two-dimensional (2D) QR code. We can generate Aztec code to sign the uploaded PDF document by following the steps mentioned earlier. However, we just need to set the QRCodeType to “Aztec”.

The following code sample shows how to generate the Aztec code and sign the PDF document using a REST API in PHP.

Generate Aztec QR Code to Sign PDF in PHP.

Generate Aztec Code to Sign PDF in PHP.

Create DataMatrix Code to Sign PDF in PHP

We can also generate DataMatrix code by following the steps mentioned earlier. However, we just need to set the QRCodeType to “DataMatrix”.

The following code sample shows how to generate the DataMatrix code and sign the PDF document using a REST API in PHP.

Create DataMatrix QR Code to Sign PDF in PHP.

Create DataMatrix Code to Sign PDF in PHP.

Verify QR Code Signatures in PHP

You can easily verify the generated QR code signatures by following the steps given below:

  1. Firstly, create an instance of the SignApi.
  2. Set the PDF file path.
  3. Define VerifyQRCodeOptions.
  4. Provide Signature Type, Text, and Code.
  5. Define VerifySettings and assign _VerifyQRCodeOptions _to VerifySettings.
  6. After that, create the VerifySignatureRequest with VerifySettings.
  7. Finally, get results by calling the verifySignatures() method.

The following code sample shows how to verify the QR code signatures using a REST API in PHP.

Try Online

Please try the following free online PDF signature tool, which is developed using the above API. https://products.groupdocs.app/signature/pdf

Conclusion

In this article, we have learned how to:

  • generate QR code in PHP;
  • sign PDF document with QR code in PHP;
  • verify e-signatures in PHP;
  • programmatically upload the PDF file to the cloud;
  • download the signed PDF file from the cloud.

Additionally, you can expand your knowledge of the GroupDocs.Signature Cloud API by referring to the documentation. We also offer an API Reference section, which enables you to interact with our APIs directly within your web browser. Should you encounter any uncertainties, please don’t hesitate to reach out to us through our forum.

See Also