Amazon UCC128 Barcode

Updated 28-Jun-2024

Updated 24-Nov-2018

Publishing Toolchain/Workflow Notes

Syntax for ISBN .eps

./bookland -o 978-0-9822972-7-8.eps 978-0-9822972-7-8

Syntax for Amazon ASIN (effectively a hyphen-less ISBN-10 of the ISBN-13)

encode128 0982297270

Take output and use Code128 Font to display

The Amazon Barcode

Note for revision: the latest version of encode128 is using different start/stop characters than what is displayed/discussed below. Need to correct this. The main point is to use encode128 encoder and the code128* fonts from the same developer, which work well together.

Anyone wishing to use Amazon Advantage (for media publishers) or Amazon Fulfillment, needs to include barcodes on individual items, so that they are stored and selected as individual units. Amazon provides the following information in one of their PDFs:

Amazon Barcode Guidelines

If you would like to print barcodes directly on Units, use the UCC128 barcode. The UCC128 barcode standards are available on the Internet.

6.2. Amazon uses the UCC128 barcode (font) to encode the FNSKU or the ASIN in the barcode. We don't use any leading or trailing digits (application identifiers or checksum digits).

6.3. The full specification is UCC128 code set A (this is the code set that supports alphanumeric data).

6.4. If you are building the barcode from scratch, you can review the standards or purchase software (there are many barcode applications available for free or at reasonable prices).

To someone who doesn't know jack about barcodes, this is bewildering and unhelpful. Sure there are many barcode applications available for free or at reasonable prices but where are they, how do they work, and more importantly, which ones do the Amazon thing of UCC128 (which is not actually a name or standard of anything).

And so the adventure begins.

Code 128 A B C

First off, the 128 of Code 128 has to do with ASCII (which is 128 characters), some extended characters (all of Latin-1), and some clever compression (if compressible). Also, the GS1-128 shipping standard (formerly known as EAN) is a subset of Code 128. This means that all shipping and most product identification labels rely on all or some part of how this code works.

Secondly, the A,B,C are slightly different schemes (different character set support) which most system support all of. That is, there is code switching between the different sets, depending on what is encoded. A is A-Z, 0-9; B is A-Z, a-z, 0-9, and some punctuation; C is 00-99. B is the most common scheme (that can be used by itself, but C allows for compression if there is a pattern to the characters (e.g., repeated characters, or characters in series). If nothing fancy is needed then B is fine.

In Code 128 bar code encoding, each character consists of alternating three bars and three spaces (with a possible thickness of 1-4), a start character, a stop character, and just before the stop character is a checksum character, based on a calculation.

Note that each character in a bar code fits into 12 widths (that is, the three spaces and three lines much together add up to 12 widths). In practice, Code 128 is 11 widths, and lines and spaces are 1-4 widths in width. Each character starts with a line, and ends with a space, excluding the final end character which is 13 widths and ends with a 2-width line.

Starting and Stopping Characters

For Code 128 B Character Set, the starting character is Ñ (a capital N with an enya (tilde) overhead).The stopping character is Ó (capital O with an acute). Sometimes these are indicated as a different character, but what is most important, is having a font system that matches the control characters to be used.

Note: don't use the Code128.TTF, instead use one of these better Code 128 Fonts

Calculating the Checksum Character

The basic calculation is a modulo (remainder, after dividing by 103 non-delimiter characters) of the sum of the text string numerical values multiplied by their position. For a text string HELLO, we would see:

  • Start B = 104
  • H = 40
  • e = 69
  • l = 76
  • l = 76
  • o = 79

Formula:

> modulo 103 ((104)+(401)+(692)+(763)+(764)+(795)) > (Note the 104 for Start B, whereas if the barcode were only a number, it would Start C.) > = modulo 103 (40+138+228+304+395) > = modulo 103 (1105) > = 10 remainder 76 > 76 is the lowercase letter *L (see > Encoded: Hello is: ÑHellolÓ

Practical Note: use the command line code 128 encoder to generate the codes, and then use a Code128* font to render it, or use the bookland python script to generate an .eps file (which is better when needing an encoded ISBN barcde with all the trimmings). Bookland can't just do a barcode, but interprets even an ISBN-10 without hyphens into an ISBN-13.

Bugnote: The code-128 has a problem rendering the character for Capital-I-Diareses (which looks like a divide-by sign as well), so there has to be a fall-back to non-compressed encoding (start and end characters, plus checksum, but no clever encoding). The start and end characters from code-128 are Ò and Ó, and for non-compressed it is Ñ and Ó. A simple LibreOffice Calc implementation of code128 for non-compressed is available.

Amazon Barcode Generation

While in the very first bit of text that Amazon provides, it says it does not use leading or trailing digits or checksum digits. This is not correct (at least from Amazon generated Purchase Orders and Shipping Labels). Amazon uses a Code 128 B scheme (their start character is a B Start) but constrains the codes to A-Z, 0-9 (no lower-case alphabetic characters). They do use a checksum.

Does this really matter? Probably not. Most likely, all user/customer/vendor-generated codes (with or without start/stop/checksum) will be recognized. Implementation for bar code scanners is in software, and even most of the mobile apps that do bar code recognition support codes with and without start, stop and checksums. However, it does make sense to use the same system that Amazon implements. And of course to understand how this works in case of needing to generate missing Amazon barcodes such as Purchase Order or Shipment numbers. And so, now we know.

The simplest approach is two steps:

  • Take the given text string, use Code 128 B and calculate the checksum (as in the example above)
  • Append the start and stop control characters as well as the checksum character
  • Use Code128.TTF font, and then adjust for appropriate width and height (I use Inkscape for this)

Note that this does not use clever compression to produce fewer characters and therefore fewer bars on the barcode.

Note: Better Code 128 Fonts

Bar Code Typeface, Font, and Typography

Because characters always have the same numeric value, and the same bar code encoding, it would be simple to simply type in what will be represented (generally, capital letters and numbers only), and change the typeface, rendering the characters into bar codes. A great, open source, and free TTF font is available from

Online Encoding / Local Scripts

Note, most sites suck over time, and so even if we built a link to something that didn't suck, that would become untrue. Best to stick with code we can manage, that is forked github repositories, namely: bookland python script.

ISBN Tools for Amazon ASINs

Note that Amazon ASINs are not necessarily ISBNs but in many cases they are. When submitting an ISBN-13 as the product code, an ISBN-10 is generated (without hyphens) as the Amazon ASIN.

Note the Library of Congress ISBN Conversion Tool

Online Tools

The Barton site has a handy Barcode encoding tool that generates the start, stop, and checksum characters. This makes it easy to copy/paste into a Barcode Font text and voila, a fully generated (and editable) barcode. However, it uses an old system so the control characters do not match up with the standard found in the Code128.TTF v.2.0. Also, the Barton site has the OLD 1.2 version of the Code128.TTF font. Avoid both.

Encoding and Barcode Generation Implementations

Visual Basic / VBA

Better (though a bit old school) is using Libre Office and a macro as offered by the amazing Grand Zebu, who was also the original source of this open source font (have to enable Macros to run in security settings).

Note: this no longer runs on the latest version of Libre Office.

PHP

Somewhat bloated, half-refactored implementation in PHP (really, a great thing, but monolithic).

Javascript / Node Barcodes

The modern and well-supported tool is the JsBarcode project.