
Here x_1 is the first digit of UPC and x_12 is the check digit itself that is unknown. The check digit equation for UPC-A looks like this: Each symbology uses a specific formula for calculating the check digit. The check digit allows the barcode reader to detect certain errors that might have been introduced into the barcode for various reasons. You can get more information about UPC and other forms of barcodes from Wikipedia. I will not add the digits to the SVG but that would be a simple extension once we have the main barcode generation working. We will try to create a UPC-A barcode using pure Python. The last digit is a check digit and helps detect certain errors in the barcode. The next 10 digits represent product-specific information and the interpretation depends on the NSC. If it starts with a 2 then it is going to be interpreted as a produce item that contains a weight or price. For example, If it is a 0, 1, 6, 7, or 8, it is going to be interpreted as a typical retail product. The first digit, Number System Character, decides how the rest of the digits in the barcode will be interpreted. The symbology for UPC-A only allows storing 12 digits. I chose it for this article because it is super simple and quite a few other codes are just an extension of this. It only allows storing digits (0-9) in the bars.
Upc barcode generator code#
This is type A of the Universal Product Code barcode. In this article, we will be focusing on the UPC-A barcode. There are tons of different symbologies out there and each is prevalent in a different industry. Some symbologies allow storing alphabets but some only allow storing digits. The way the information is encoded in a barcode is called the symbology. However, printing vertical bars meant that the smears would only increase the bar height and the code would still be readable. A major reason they didn’t stay for long is that the printers would sometimes smear the ink and that would render the code unreadable. There was also a proposal for a circular bullseye barcode in the early days. The follow-up versions included a bunch of fun types of barcodes. One of the early versions just extended the dots to form vertical lines. The idea for encoding this information in the form of bars originated from morse code. No doubt the barcode later found huge commercial success in the retail industry! The idea for an automated entry system (barcode) originated when a Drexel student overheard a food chain owner asking for a system to automatically read product information during checkout. However, it took over twenty years before this invention became commercially successful. The invention was based on Morse code that was extended to thin and thick bars.

The barcode was invented by Norman Joseph Woodland and Bernard Silver and patented in the US in 1951. It seems like barcodes have been there even before I was born.
Upc barcode generator how to#
I will take you on a guided tour of how a barcode works and how to create a super simple barcode generator for the Universal Product Code (UPC-A) using pure Python.ĭisclaimer: I have borrowed some code and ideas from Hugo for this article. This article is in a similar vein as my “Understanding and Decoding a JPEG Image using Python” article.

There is no substitute for learning more about something by creating it from scratch so that is exactly what I did. It seemed like I would learn a lot from diving deeper and implementing a barcode generator from scratch. I have known for a long time about how they work in theory but I never did enough research on it. Hi everyone! 👋 I have always been fascinated by barcodes and QR codes. Understanding and Generating a UPC-A barcode using Python April 12, 2021
