How to generate barcode and sign document using Python
How to generate barcode and sign document using Python
Leave feedback
On this page
Barcodes represent textual information as a quite small image that could be automatically scanned. Such an approach brings new opportunities in the computer processing of documents like sorting or moving through a business workflow. In this article, we will discuss useful ways to sign electronic documents with data encrypted in Bar or QR codes using Python.
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
How to sign PDF files with a barcode
It is a common problem to add additional data to various types of business documents. Such a document may look as in the picture below. One of the most useful ways is to place a barcode directly on the document page.
Signing a document with a Codabar in Python
To generate a barcode and sign a particular document with it:
Instantiate the Signature class providing a path to the source document or document stream.
Create the BarcodeSignOptions instance and set up all demanded fields.
Invoke the sign method to process the document, providing the output file path and sign options.
A document signed with a Codabar might look like in the picture below. The Codabar format was developed for printed documents and might be useful in office document flow.
The Barcode Generator Online App provides an opportunity to try document signing with barcodes for free.
Barcode and image generation in Python
Another way to improve documents is to generate the barcode 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 BarcodeSignOptions class instance and set up all the demanded fields.
Instantiate the PreviewSignatureOptions object providing the methods for creation and releasing.
Invoke the generate_signature_preview method to obtain the barcode image as a stream.
Use the resultant barcode stream in any possible way.
importgroupdocs.signatureassignaturefromioimportBytesIO# Create a memory stream to store the barcode imageresult=BytesIO()# Setup barcode signature optionsbarcode_options=signature.BarcodeSignOptions()barcode_options.encode_type=signature.BarcodeTypes.CODE93barcode_options.text="Case 148.01"# Create preview optionspreview_options=signature.PreviewSignatureOptions(barcode_options,lambdaoptions:result,# Create page streamlambdaoptions,stream:None# Release page stream)# Generate image to streamsignature.Signature.generate_signature_preview(preview_options)
An image containing the generated barcode might look in this way:
Get a Free API License
In order to use the API without evaluation limitations, you can get a free temporary license.
Conclusion
To sum up, some useful ways of processing documents and barcodes were discussed in this article. Using Python improves the productivity of such actions dramatically.
In addition, you can use the Barcode Generator Online App to generate barcodes and/or sign your files with barcodes 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.