Generate Patch Code in Python

A patch code is a pattern of specific vertical bars and spaces used in document imaging. These codes are used to instruct a scanner to perform a certain action, such as separating documents, starting a new batch, or ignoring a blank page. In this article, we will learn how to generate a high-quality patch code in Python.

The following topics will be covered in this article:

  1. What is Patch Code or Patch Barcode
  2. Python API to Generate Patch Code - Free Download
  3. Create Patch Code in Python
  4. Generate Patch Code for A4 Paper Size
  5. Patch Code for US Letter Page
  6. Generate Patch Code with QR Code
  7. Patch Code Types
  8. Get a Free License
  9. Generate Patch Code Online
  10. Learning Resources

What is Patch Code or Patch Barcode

A patch code or a patch barcode is a series of 6 possible patterns/permutations of bars and spaces, where the first and last bar are always black, and the middle four can be either black or white, corresponding to the digits 1-0 in binary. For example, a Patch T code, which is often used to separate documents, corresponds to the pattern black-white-black-white-black-black.

Patch codes are often used in high-volume scanning operations, where it’s important to automate as much of the process as possible, including document separation, batch control, and quality control operations. This allows operators to scan a large stack of documents in a single pass, while still maintaining control over how those documents are processed and stored.

Python API to Generate Patch Code - Free Download

We’ll use Aspose.BarCode for Python to make patch codes. It is a versatile and powerful API for barcode creation and manipulation. It allows developers to create and read different types of 1D and 2D barcodes. Over 60 barcode symbologies are supported, including Code 39, Code 128, and QR Code. It also supports EAN, UPC, PDF147, Data Matrix, and complex barcodes.

Please either download the package or install the API from PyPI using the following pip command in the console:

pip install aspose-barcode-for-python-via-net 

Create Patch Code in Python

We can create patch code in Python by following the steps given below:

  1. Create an instance of the BarcodeGenerator class and set the required EncodeTypes as PATCH_CODE.
  2. Next, specify the input code text.
  3. Optionally, specify Barcode customization options.
  4. Finally, call the save() method to save the generated Barcode image at the given file path.

The following code sample shows how to create a patch barcode in Python.

Create Patch code in Python.

Create Patch Code in Python.

Generate PatchCode for A4 Paper Size

We can generate a patch code for A4 paper size with portrait or landscape orientation. The patch barcode appears on the page borders. Please follow the steps mentioned earlier to generate a patch code for A4 paper size. However, we just need to specify patch_format as A4.

The following code sample shows how to generate a patch code for A4 paper size in Python.

Generate PatchCode for A4 Paper Size

Generate PatchCode for A4 Paper Size.

The A4 patch format works for A4 pages in portrait orientation. However, if you want to generate a patch barcode for A4 pages in landscape format, specify patch_format as A4_LANDSCAPE.

The following code sample shows how to generate a patch code for A4 Landscape in Python.

Generate PatchCode for A4 Paper Size

Generate PatchCode for A4 Landscape.

Patch Code for US Letter Page

Similarly, we can also generate patch codes for US letter pages in portrait or landscape orientation. For this purpose, we need to specify US_LETTER as the patch_format for portrait and US_LETTER_LANDSCAPE for landscape orientation.

The following code sample shows how to generate a patch code for US letter page size in Python.

Generate PatchCode with QR Code

By following the steps mentioned earlier, we can add a QR code to the patch code. However, we need to specify the extra_barcode_text and location properties.

The following code sample shows how to generate PatchCode with QR Code in Python.

Generate PatchCode with QR Code

Generate PatchCode with QR Code.

Patch Code Types

The Aspose.BarCode for Python library supports six different PatchCode patterns. These patterns are Patch I, Patch II, Patch III, Patch IV, Patch T, and Patch VI.

The following code sample shows how to generate various patch code patterns in Python.

Patch Code Types

Patch Code Types.

Barcode Python Library - Get a Free License

Aspose offers a free evaluation version to test the library’s features and capabilities. Please get a free temporary license to test the library for yourself without evaluation limitations.

Generate Patch Code Online

You may generate Patch code online for free using the online PatchCode generator, which is developed using this API. Please access the free online PatchCode generator in your browser using the following link:

https://products.aspose.app/barcode/generate/patchcode

Patch Barcode in Python - Learning Resources

You can learn more about generating patch code and explore other features of Aspose.BarCode for Python using the resources given below:

Conclusion

In this blog post, we learned how to generate a patch code in Python using Aspose.BarCode for Python. The step-by-step guide and code sample demonstrate how to create various patterns of patch codes programmatically. Aspose.BarCode for Python is an extremely useful tool for developers. You can easily install the library and generate barcodes in your Python application. In case of any ambiguity, please contact us on our free support forum.

See Also