C# Code 128 Generator Library SDK

Integration & Developer Guide for Code 128 linear barcode image generation in C#

Generate Code 128 barcode images in Visual C# .NET with complete sample C# source code, no font





In this C# tutorial, you will learn how to generate, print Code 128 barcode images in ASP.NET and Windows applications using C#.

  • Fully compatible with ISO/IEC 15417 standard
  • Easy to use C#/VB .NET to generate Code 128 with full ASCII and Extended ASCII characters
  • Print high resolution Code 128 barcode image with specified width and height
  • Customize Code 128 with various module colors and background color, including transparent background
  • Easy to embed Code 128 barcode in web page, Crystal Reports, RDLC reports
  • Enable create Code 128 in .NET Core, ASP.NET Core, MVC, WinForms, WPF apps

How to create Code 128 barcode images using C# in ASP.NET, Windows app

  1. Download .NET Code 128 Barcode Generator SDK
  2. Install C# library to create Code 128 images in ASP.NET and Windows projects
  3. Step by Step Tutorial




























Code 128 Barcode Introduction

Top
Code 128, also known as ANSI/AIM 128, ANSI/AIM Code 128, USS Code 128, Uniform Symbology Specification Code 128, is a very capable linear barcode of excellent density, high reliability.

C# Code 128 Generator is one of the functions in OnBarcode's .NET Barcode Generation Controls, which supports generating & printing Code 128 and 20+ other linear & 2D bar codes for C# applications.
OnBarcode C# Barcode Generator makes it easy to generate, create Code 128 and other linear & 2d barcodes in Microsoft Word.
OnBarcode provides several Code 128 Generator components and software, including Code 128 in .NET, Code 128 in Java, Code 128 in ASP.NET, Code 128 in VB.NET, Code 128 Generator.
This document is providing a detailed C# source code about generating Code 128 barcodes in C# class using C# Barcode generation component. Complete Code 128 custmoization settings is included in C# Code 128 generation guide.


Code 128 Barcode Data Characters Encoding using C#

Top


Code 128 data character set

Code 128 barcode supports the following data characters

  • All 128 Full ASCII characters defined in ISO/IEC 646
  • Extended ASCII characters are also supported with Function Character (FNC4) used. (By default are values 128 - 255 of ISO/IEC 8859-1, Latin Alphabet 1)
  • 4 non-data function characters
  • 4 code set selection characters
  • 3 Start characters
  • 1 Stop character


Code 128 Data Code Sets in C#

Code 128 barcode has three unique data character code sets.
  • Code Sets A
  • Code Sets B
  • Code Sets C
Each code set includes a subset of the full ASCII character set together with various auxiliary characters.

Using OnBarcode C# Code 128 generator library, you can ignore the Code 128 code set, and the library will choose the right starting code set for you.

You can set the property Type to BarcodeType.CODE128, and the library will automatically select the right code set for you.

If you want to choose the Code 128 code set manually, you can set the Type property to
  • BarcodeType.CODE128A for Code Set A
  • BarcodeType.CODE128B for Code Set B
  • BarcodeType.CODE128C for Code Set C
            Linear code128 = new Linear();

            // encode data characters
            code128.Data = "Code 128";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;


Code 128 Function characters using C#

Code 128 Function Characters (FNC) define instructions to the bar code reading device to allow for special operations and applications.
  • FNC1: It is for GS1 system. You can find more information about GS1-128 in C#
  • FNC2: It is for message append.
  • FNC3: It instructs the bar code reader to interpret the data from the symbol containing the FNC3 character as instructions for initialization or reprogramming of the bar code reader.
  • FNC4: It is used to represent an extended character set (byte values 128 to 255 in ISO/IEC 8859-1 by default)
Using C# Code 128 barcode generator, you do not need input function characters. Our library will automatically encode them for you.


Code 128 check digit character in C#

Code 128 barcode contains a mandatory check digit (checksum) character, which is based on module 103 (mod 103).

The Code 128 check digit will not be displayed in the human readable interpretation (barcode text), and it will not be returned by the barcode decoder also.

In barcode library class Linear, the property "AddCheckSum" is not appliable for Code 128. The library will always calculate and create a check digit character before the Stop character.
            // encode data characters
            code128.Data = "Code 128";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;
            // AddCheckSum is not working for barcode Code 128. 
            code128.AddCheckSum = true;


Code 128 Barcode Human Readable Interpretation (HRI)

Top
HRI should be printed with the Code 128 symbol barcode. Text can be printed anywhere in the area surrounding the barcode, as long as quiet zone boundaries are not violated.

C# source code to render HRI (data text) below the Code 128 symbol
            Linear code128 = new Linear();

            // encode data characters
            code128.Data = "Code 128 HRI";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;


C# source code to render HRI (data text) above the Code 128 symbol.

Note: to draw and render HRI above the barcode symbol, you need set property "TextMargin" to a negative value.
            Linear code128 = new Linear();

            // encode data characters
            code128.Data = "Code 128 HRI";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;

            code128.X = 1;
            code128.Y = 60;

            code128.TextMargin = -75;

            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 20;
            code128.BottomMargin = 0;


Code 128 Barcode Dimension Size in C#

Top
Using C# Code 128 barcode generator, you can apply the following barcode dimension size settings:
  • UOM: Unit of measure. You can choose PIXEL, CM or INCH.
  • X: Width of narrow element. The mimumum bar width is defined by the application specification
  • Y: Bar module height.
  • LeftMargin, RightMargin: Quiet zone. the minimum width of quiet zone is 10X.
You can view the Code 128 Barcode Size Calculator here.

A sample C# source code to set Code 128 barcode image sizes.
            Linear code128 = new Linear();

            // encode data characters
            code128.Data = "Code 128";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;


            // Unit of meature for all size related setting in the library. 
            code128.UOM = UnitOfMeasure.PIXEL;

            code128.X = 2;
            code128.Y = 60;
            code128.LeftMargin = 10;
            code128.RightMargin = 10;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;


 

Generate, encode GS1 data in Code 128 using C#

The GS1 system originated in the United States and was established in 1973 by the Uniform Product Code Council, known until recently as the Uniform Code Council, Inc.

Code 128 barcode symbology is a valid data carrier for GS1. To create GS1 data in Code 128, please view barcode EAN 128 / GS1-128.




 

Code 128 barcode property settings in C#

.NET Barcode Generator library has provided 20+ property settings to customize the generated Code 128 barcode image. You view the list of Code 128 barcode property settings.




 

Generate, encode Non-printable chars in Code 128 using C#

Sample C# source code to encode non printable chars '[CR]' (Carriage Return) in Code 128 barcode
            Linear code128 = new Linear();

            // encode non printable char '[CR]', between 'a' and 'b'
            code128.Data = "a~013bc";
            // Barcode symbology type. Code 128 supports types: CODE128, CODE128A, CODE128B, CODE128C.
            code128.Type = BarcodeType.CODE128;

            code128.ProcessTilde = true;

            /*
            * Barcode Image Related Settings
            */
            // Unit of meature for all size related setting in the library. 
            code128.UOM = UnitOfMeasure.PIXEL;
            // Bar module width (X), default is 1 pixel;
            code128.X = 1;
            // Bar module height (Y), default is 60 pixel;
            code128.Y = 60;
            // Barcode image left, right, top, bottom margins. Defaults are 0.
            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;
            // Image resolution in dpi, default is 72 dpi.
            code128.Resolution = 72;
            // Created barcode orientation.
            //4 options are: facing left, facing right, facing bottom, and facing top
            code128.Rotate = Rotate.Rotate0;

            /*
            * Linear barcodes human readable text styles
            */
            // Display human readable text under the barcode
            code128.ShowText = true;
            // Display checksum digit at the end of barcode data.
            code128.ShowCheckSumChar = true;
            // Human readable text font size, font family and style
            code128.TextFont = new Font("Arial", 9f, FontStyle.Regular);
            // Space between barcode and text. Default is 6 pixel.
            code128.TextMargin = 6;

            // Generate Code-128 and encode barcode to png format
            code128.Format = System.Drawing.Imaging.ImageFormat.Png;

            code128.drawBarcode("W://Projects//Test-Output//OnBarcode.com//csharp-code128-non-print.png");




Source code to create Code-128 Barcodes in C# class example

Top
Sample C# source code: How to generate Code 128 in C# class?


More C# Barcode Generation Tutorials for Each Barcode

Top

Barcode Control for C#.NET - Bar Code Type Generation

OnBarcode is a market-leading provider of barcode imaging generator, reader controls and components for ASP.NET, Windows Forms, WPF, as well Java, Android, iOS (iPhone, iPad) across all major enterprise development platforms. We provides comprehensive tutorials and how-tos for various linear, 2d barcode information, such as C# in ASP.NET, C# .NET, C# Barcode Encoding, C# Barcode Image, VB.NET in ASP.NET, VB.NET Winforms, VB.NET Barcode Encoding. OnBarcode barcode products are supported by RasterEdge ASP.NET Document Viewer, which supports ASP.NET PDF Viewer, ASP.NET MVC Document Viewer, ASP.NET PDF Editor, MVC PDF Viewer. And provide high quality C# Convert PDF to Tiff, C# Convert PDF to Word, C# Convert PDF to HTML, C# Convert PDF to Jpeg images, and their easy and simple documents, like C# PDF SDK, C# extract text from PDF, C# Compress PDF, Print PDF in C# and C# extract image from PDF.
Terms of Use | Privacy Policy
Copyright © OnBarcode.com . All rights reserved.