QR Code (Quick Response code) is a type of machine-readable Matrix barcode in the form of an array of black and white squares. It is an optical label that contains information readable using a QR reader. We can generate QR codes programmatically and sign the documents and images on the cloud. In this article, we will learn how to generate a QR code to sign PDF documents using REST API in PHP.
The following topics shall be covered in this article:
- QR Code Generator REST API and PHP SDK
- Generate QR Code to Sign PDF in PHP
- Generate Aztec QR Code to Sign PDF in PHP
- Create DataMatrix QR Code to Sign PDF in PHP
- Verify QR Code Signatures in PHP
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
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:
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:
- Firstly, create an instance of the SignApi.
- Next, provide the input PDF file path.
- Then, set the output file path.
- Next, initialize the SignQRCodeOptions object.
- Then, set the QRCodeType to “QR”. Moreover, set the text, and its position.
- Optionally, set options such as Page, RotationAngle, HorizontalAlignment, Border, Padding etc.
- After that, create the createSignaturesRequest with the defined SignSettings.
- 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.
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.
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.
Verify QR Code Signatures in PHP
You can easily verify the generated QR code signatures by following the steps given below:
- Firstly, create an instance of the SignApi.
- Set the PDF file path.
- Define VerifyQRCodeOptions.
- Provide Signature Type, Text, and Code.
- Define VerifySettings and assign _VerifyQRCodeOptions _to VerifySettings.
- After that, create the VerifySignatureRequest with VerifySettings.
- 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.
Please try the following free online PDF signature tool, which is developed using the above API. https://products.groupdocs.app/signature/pdf
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.
Besides, you can learn more about GroupDocs.Signature Cloud API using the documentation. We also provide an API Reference section that lets you visualize and interact with our APIs directly through the browser. In case of any ambiguity, please feel free to contact us on the forum.