How to generate QR Code and sign document using Python
How to generate QR Code and sign document using Python
Leave feedback
On this page
The generated QR Code can be downloaded and used to add to the business contracts and official documents. Any QR Code contains unique textual information that confirms the identity of the signer or authorizes the business document. QR Code verification could be performed automatically by reading the contents of the QR Code embedded data. These signatures could be scanned automatically. The QR Code allows keeping over 2 Kilobytes of data.
Python API for Electronic Signatures
GroupDocs.Signature for Python via .NET provides API for signing a wide range of document formats. Moreover, API includes special abilities for additional document content processing. Supported formats are PDF, Microsoft Word, Microsoft PowerPoint, Microsoft Excel, PNG, JPEG, and many others.
Use pip to install the package:
pip install groupdocs-signature
Signing a document with an Event QR-code in Python
Sometimes it is needed to inform coworkers about business events. In such cases, an Event QR code can provide all the required information in a very effective way. This topic describes how to sign a PDF document with the generated Event QR code.
Instantiate the Signature class providing the path to the source document or document stream.
Set event data in the Event object instance.
Create the QrCodeSignOptions object and set up all demanded fields.
Invoke the sign method to process the document, providing output file path and sign options.
importgroupdocs.signatureassignatureimportgroupdocs.signature.domainasgsdfromgroupdocs.signature.optionsimportQrCodeSignOptionsfromdatetimeimportdatetime# Initialize signature handlersignature_handler=signature.Signature("source.pdf")# Provide event dataevent_qr=signature.Event()event_qr.title="Meeting"event_qr.description="Productivity issues"event_qr.location="room 408"event_qr.start_date=datetime(2022,6,19,15,30,0)event_qr.end_date=datetime(2022,6,19,17,0,0)# Setup QR code signature optionsqr_options=QrCodeSignOptions()qr_options.horizontal_alignment=gsd.HorizontalAlignment.RIGHTqr_options.vertical_alignment=gsd.VerticalAlignment.BOTTOMqr_options.encode_type=gsd.QrCodeTypes.QRqr_options.text=""qr_options.data=event_qr# Sign documentsignature_handler.sign("signed_event.pdf",qr_options)
The result of signing a document may look like the picture below. Such QR codes can be very useful for organizing events.
To try signing documents with QR codes for free, you may use the QR Code Generator Online App.
QR Code image generation in Python
Another way to improve documents is to generate the QR code first and then add it to documents using third-party tools. For this case, it is possible to generate code as an image.
Create the QrCodeSignOptions instance and set up all demanded fields.
Instantiate the PreviewSignatureOptions object providing the methods for creation and releasing.
Invoke the generate_signature_preview method to obtain the QR code image as a stream.
Use the resultant QR Code stream in any possible way.
importgroupdocs.signatureassignaturefromioimportBytesIOimportgroupdocs.signature.domainasgsdfromgroupdocs.signature.optionsimportQrCodeSignOptions,PreviewSignatureOptions# Create a memory stream to store the QR code imageresult=BytesIO()# Setup QR code signature optionsqr_options=QrCodeSignOptions()qr_options.encode_type=gsd.QrCodeTypes.CODE93qr_options.text="Case 148.01"# Create preview optionspreview_options=PreviewSignatureOptions(qr_options,lambdaoptions:result,# Create page streamlambdaoptions,stream:None# Release page stream)# Generate image to streamsignature.Signature.generate_signature_preview(preview_options)
An image with the generated QR Code may look as below:
Get a Free API License
To use the API without evaluation limitations, you can get a free temporary license.
Conclusion
To sum up, some useful ways of processing documents with QR codes were discussed in this article. Using Python improves the productivity of such actions dramatically.
In addition, you can use the QR Code Generator Online App to generate QR codes and/or sign your files with QR codes for free.
Read the documentation to learn how to use GroupDocs.Signature in your Python applications. Also, you may discuss any questions or issues at the GroupDocs forum.