Generating Code 128C Barcodes in Blazor: A Step-by-Step Guide

Introduction
Barcodes, in essence, are machine-readable representations of data that encode information in a series of black and white bars. Code 128C is a high-density barcode format that is optimized for numeric data, encoding two digits per symbol, making it particularly compact and efficient for numerical datasets. This makes it ideal for use in industries like logistics, retail, and inventory management.
How Code 128C is Rendered


Understanding the Code 128C Algorithm
1. Append the Start Symbol
- Start by appending the start symbol to the barcode sequence.
2. Map Two-Digit Numbers to Table Positions
- The input number string is divided into two-digit pairs:
- For example, "123456" becomes "12", "34", "56".
- Each two-digit pair is treated as a single number between 00 and 99.
- "12" → Position 12 in the table → Bar sequence "11011001100".
- "34" → Position 34 in the table → Bar sequence "11100101100".
If the input string has an odd number of digits, a leading 0 is added to make it even. For example:
"12345" → "012345".
3. Calculate the Checksum
- Start with the value of the start symbol (105).
- For each two-digit pair, multiply its position (1-based index) by its value:
- For "12" (value 12) at position 1: 12 × 1 = 12.
- For "34" (value 34) at position 2: 34 × 2 = 68.
- For "56" (value 56) at position 3: 56 × 3 = 168.
- (105 + 12 + 68 + 168) % 103 = 50.
4. Append the Checksum Bar Sequence
- Use the calculated checksum value (50) to look up the corresponding bar pattern in the table.
- Position 50 in the table → Bar sequence "11001110100".
5. Append the End Symbol
- Append end symbol to the barcode sequence.
Rendering of Barcode 128c in Blazor
Aliasing problem (detected on MAUI application)
What is Antialiasing?
Antialiasing is a visual effect used to smooth the edges of digital graphics. When adjacent elements, such as the narrow bars in a barcode, are rendered separately, antialiasing can create faint lines or gaps between these elements, making the barcode appear inconsistent. This happens especially when the rendering engine attempts to “blend” the edges of two closely aligned shapes with the background.
Solution: Grouping Zeros and Ones
- A binary sequence like "1110001111" would be grouped into:
- "111" (black bar of width 3)
- "000" (white space of width 3)
- "1111" (black bar of width 4).
Testing and Verifying the Barcode

Try it Yourself
Verifying Results





