KA.Barcode for .NET Suite
How to Generate Code 128 in C# Application
How to Generate Linear Code 128 Barcode Images in C#, ASP.NET, WinForms, Crystal & RDLC

C# Code 128 barcode generator library: create, render, print barcode code 128 from string with auto checksum, free c# example. no font

  • Print 1D Code 128Auto, Code 128A, Code 128B and Code 128C in Visual C#.NET class library
  • Create Code 128 barcodes in ASP.NET websites, WinForms, Crystal Reports as well as RDLC Reports
  • Advanced calculation to automatically add Code 128 checksum digit compatible with related specification
  • Offer rich setting options for generated images including size, orientation, resolution, font, etc
  • Support multiple Code 128 barcode image formats, including gif, jpeg, png, tiff and bitmap
  • Provide royalty-free and permanent license for this C# Code 128 barcode library
C# Code 128 Barcode Generator Introduction
KA.Barcode Generator for .NET Suite is the best quality barcode encoder which adds 1D Code 128A, Code 128B, Code 128C barcoding features in .NET. When a Code 128 image is generated in C#, the user-friendly interface allows developers to easily adjust various barcoding settings and produce images with a fixed size.
What Is A Code 128 Barcode
Code 128, also named as ANSI/AIM 128, ANSI/AIM Code 128, USS Code 128, Uniform Symbology Specification Code 128, Code 128 Code Set A, Code 128 Code Set B, Code 128 Code Set C, Code 128A, Code 128B, Code 128C, is a self-checking linear barcode which encodes 128 ISO/IEC 646 characters.
Code 128 Data Encoding
Code 128 encodable character set
  • All 128 characters of ASCII

  • Extended ASCII (ISO 8859-1 defined values 128-255)
Generate Barcode Image in Specified Width and Height
  • Set property AutoSizeAdjust to true

  • Set property DPI to be the same or higher as your printer's resolution

  • Set property BarcodeUnit to inch or cm

  • Set property BarCodeWidth and BarCodeHeight to your required image width and height
Code 128 Property Settings
Class Attribute HTTP Attribute Default Value Note
Symbology symbology Code128Auto Barcode symoblogy type.

Valid values for Code 128 are:
  • KeepAutomation.Barcode.Symbology.Code128Auto

  • KeepAutomation.Barcode.Symbology.Code128A

  • KeepAutomation.Barcode.Symbology.Code128B

  • KeepAutomation.Barcode.Symbology.Code128C
CodeToEncode code-to-encode "128" Barcode value to encode.
  • Valid Data Scope for Code 128 Auto (KeepAutomation.Barcode.Symbology.Code128Auto):

    All 128 characters of ASCII (ASCII values from 0 to 127)

  • Valid Data Scope for Code 128 Set A (KeepAutomation.Barcode.Symbology.CODE128A):

    Supports ASCII values from 0 to 95

  • Valid Data Scope for Code 128 Set B (KeepAutomation.Barcode.Symbology.CODE128B):

    Supports ASCII values from 32 to 127

  • Valid Data Scope for Code 128 Set C (KeepAutomation.Barcode.Symbology.CODE128C):

    Supports pairs of digits
ChecksumEnabled checksum-enabled false This property is not applied here. Barcode SDK will always add a check character between encoded data and stop character (modulo 103).
ImageFormat image-format ImageFormat.Png Barcode encoded image format.
Barcode Size
AutoSizeAdjust auto-size-adjust false If true, barcode X, Y module will be auto-adjusted.
BarcodeUnit barcode-unit BarcodeUnit.Pixel Unit of measure for all size related settings. 0: pixel; 1: inch; 2: cm.
X x 1 Barcode module width (narrow bar).
Y y 50 Linear barcode bar height / 2D barcode module height.
LeftMargin left-margin 0 Barcode image left margin.
RightMargin right-margin 0 Barcode image right margin.
TopMargin top-margin 0 Barcode image top margin.
BottomMargin bottom-margin 0 Barcode image bottom margin.
DPI dpi 72 Barcode image resolution in dpi.
Orientation orientation Orientation.Degree0 Barcode rotation angle.
BarCodeWidth barcode-width 0 Whole barcode width.
BarCodeHeight barcode-height 0 Whole barcode height.
Barcode Text Style
DisplayText display-text true Set to true, displaying barcode value text, otherwise do not display.
DisplayChecksum displace-checksum true Set to true, displaying barcode checksum digit, otherwise do not display.
TextFont text-font new Font(" Arial", 10 f, FontStyle.Regular) Barcode text font style.
TextMargin text-margin 6 Margin between barcode and text.
How to Generate Code 128 in ASP.NET Using C#
Developers can also generate linear Code 128 barcode images in ASP.NET Web applications using this barcode creator control SDK. High-quality Code 128A, Code 128B and Code 128C barcodes can be easily created in ASP.NET websites with component drag-and-drop or Visual C# class library and console applications. What also supported is Code 128 generation in Microsoft IIS. For more information, see How to print barcode in Visual C# with ASP.NET web control.
How to Paint Code 128 in .NET Windows Forms Using C#
With this .NET barcode generator class library dll, developers will find it so easy to paint and generate a Code 128 barcode image in Windows Forms applications. You can either drag the control from Toolbox for dynamic barcode generation, or create and save Code 128 graphics to local files with Visual C#.NET class libray. Turn to this page to view more: How to create barcode in .NET WinForms with Visual C#.
How to Print Code 128 in Crystal Reports Using C#
Do you want to print and embed a Code 128 barcode (support code set A, B, and C) in Crystal Reports? This .NET barcode encoder allows you to print multiple Code 128 barcode images in Crystal Reports in no time! All barcode settings are available for adjustment through Visual C# programming. Refer to: How to create barcode in Crystal Reports with Visual C#.
How to Add Code 128 in RDLC Reports Using C#
KeepAutomation barcode generator SDK for .NET Suite is easy to use and it enables developers to add barcoding features into RDLC Reports. With this encoder, you will find it a piece of cake to generate Code 128 barcodes in Visual Studio 2005/ 2008/ 2010 ReportViewer Local Reports (RDLC). Here is the detailed developer guide: How to create barcode in RDLC Reports with C# code.
How to Generate Code 128 in .NET Applications with C#
In order for you to generate high-quality Code 128 barcodes in Class Library or Console Applications, we provide complete Visual C#.NET demo code here. All Code 128 parameters mentioned below can be adjusted as you like. Just make sure you have added this .NET barcode encoder dll to project reference initially.
C# Sample code

BarCode code128 = new BarCode();
code128.Symbology = KeepAutomation.Barcode.Symbology.Code128Auto;
code128.CodeToEncode = "Code128Csharp";

//Apply checksum for Code 128 barcode.
code128.ChecksumEnabled = true;

// Print Code 128 in specified image format like Png, Jpeg, Gif, Tiff, Bmp, etc.
code128.ImageFormat = ImageFormat.Png;

// Display checksum in the Code 128 human-readable text
code128.DisplayChecksum = true;

// Set Code 128 image size

// Code 128 unit of measure, Pixel, Cm and Inch supported.
code128.BarcodeUnit = BarcodeUnit.Pixel;
// Code 128 image resolution in DPI.
code128.DPI = 72;
// Code 128 bar module width (X dimention)
code128.X = 3;
// Code 128 bar module height (Y dimention)
code128.Y = 60;
// Image left margin size, a 10X is automatically added according to
code128.LeftMargin = 0;
// Image left margin size, a 10X is automatically added according to
code128.RightMargin = 0;
// Code 128 image top margin size
code128.TopMargin = 0;
// Code 128 image bottom margin size
code128.BottomMargin = 0;
// Code 128 image orientation, 0, 90, 180, 270 degrees supported.
code128.Orientation = KeepAutomation.Barcode.Orientation.Degree0;

// Set Code 128 human readable text

// Display human readable text
code128.DisplayText = true;
code128.TextFont = new Font("Arial", 10f, FontStyle.Regular);
// Space between barcode and text beneath.
code128.TextMargin = 6;

// Generate Code 128 barcodes in image format PNG

/* Create Code 128 barcodes in Stream object
code128.generateBarcodeToStream(".NET System.IO.Stream Object");

Draw & Print Code 128 barcodes to Graphics object
code128.generateBarcodeToGraphics(".NET System.Drawing.Graphics Object");

Generate Code 128 barcodes & write to byte[]
byte[] barcodeInBytes = code128.generateBarcodeToByteArray();

Generate Code 128 barcodes & encode to System.Drawing.Bitmap object
Bitmap barcodeInBitmap = code128.generateBarcodeToBitmap();