Guide for C#
Core Document Formats
Additional Features
Code 128

C# Imaging - C# Code 128 Generation Guide

Generate Code 128 Using C#.NET Barcode Image Creator SDK

Visual C#
Home > .NET Imaging SDK > C# > Generate Code 128 Barcode
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

C# Code 128 Barcode Overview
RasterEdge is a professional Code 128 barcode generating and reading SDK provider. With our SDK, C#.NET developers will have ability to write 1D and 2D barcodes on images and documents with accuracy at high speed. All the generated Code 128 barcodes are compatible with ISO / IEC+Code128+15417-2007 barcode symbology specification and are suitable for all printers.
  • Code 128 A, Code 128 B, Code 128 C and auto modes supported for C# barcode generating
  • Include advanced algorithm to calculate and add checksum digit
  • Automatically add minimum left and right margins that go with specification
  • Optional to hide or display data text under Code 128 barcode images in C#
  • Easy to adjust Code 128 size in C# through BarcodeWidth, BarcodeHeight, X (bar width), Y (bar height)
  • Provide C# code to create single or multiple Code 128 barcode(s) on png, jpeg, gif, and bmp image files and several documents
  • Customize resolution to fit for all printers for high-quality Code 128 image output
This C#.NET Code 128 barcode generating tutorial is divided into three sections with respective example:
  • Draw Code 128 barcode on png, jpeg, gif, bmp images, etc.
  • Create Code 128 on PDF, multi-page TIFF, Word, Excel and PowerPoint documents
  • Code 128 property table and C# example coding
This tutorial focuses on how to generate Code 128 barcode images using C# class code in .NET Class Library application. In addition, here are more tutorials for Barcode Creation in VB.NET, Barcode Creation in ASP.NET, and Barcode Creation in .NET WinForms.
Draw Code 128 Barcode on Png, Jpeg, Gif, & Bmp in C#
C#.NET users can easily create single or multiple Code 128 image(s) independently, or you can draw and add Code 128 barcodes on various image files including popular formats like JPG, JPEG, BMP, PNG, and GIF.
Users only need to load your local image and draw Code 128 barcode on the image (after specifying location and Code 128 settings), then the barcode is drawn on the picture! Copy the C# sample code below to your .NET imaging program for a test now! If you have any questions concerning the barcode properties, refer to the table below or contact the customer support service!
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");
Create Code 128 on PDF, Multi-Page TIFF, Word, Excel and PPT
Demonstrated here is the Visual C# 2005 sample code to create Code 128 barcode images on these documents: PDF, multi-page TIFF, Word, Excel and PowerPoint. Developers are allowed to change the local document to be embedded, the barcode location on the specific page and also the Code 128 parameters like resolution, sizing, check digit, etc.

Create Code 128 on Defined PDF Document Area

PDFDocument doc = new PDFDocument("c:/Sample.pdf");
PDFPage page = (PDFPage)doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution

// add this barcode image to this page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save the changes
doc.Save(@"c:/barcode.pdf");

Create Code 128 on Certain TIFF Document Page

// load TIFF document. You can also load document like PDF, Word, Excel & PPT
TIFFDocument tiff = new TIFFDocument(@"c:\sample.tiff");

// get the first page
BasePage page = tiff.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to TIFF document
tiff.Save(@"c:\barcode.tiff");

Create Code 128 on Microsoft Office Word Document

// construct an DOCXDocument
DOCXDocument doc = new DOCXDocument(@"c:/Sample.docx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.docx");

Create Code 128 on Microsoft Excel Document

// construct an XLSXDocument
XLSXDocument doc = new XLSXDocument(@"c:/Sample.xlsx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 3.0F;
barcode.Resolution = 90;
barcode.Rotate = Rotate.Rotate90;

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.xlsx");

Create Code 128 on Microsoft PowerPoint Document

// construct an PPTXDocument
PPTXDocument doc = new PPTXDocument(@"c:/Sample.pptx");

// get the first page
BasePage page = doc.GetPage(0);

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data
barcode.X = 4.0F;
barcode.Resolution = 72;

// add barcode image to the first page
REImage barcodeImage = barcode.ToImage();
page.AddImage(barcodeImage, new System.Drawing.PointF(100f, 100f));

// save changes to the file
doc.Save(@"c:\barcode.pptx");
Code 128 Property Table and C# Code
With the help of following table, C#.NET developers can set Code 128 parameters with a few steps.
CODE 128 SETTING+
CODE 128 SETTING-
Type CODE128
Data Format
UOM(Unit of Measure)
Rotate
BarAlignment Resolution(DPI)
AutoResize AddCheckSum
X(Bar Width) ShowText
Y(Bar Height) TextFontSize
BarcodeWidth TextMargin
BarcodeHeight TextFontName
LeftMargin TextColor
RightMargin TextFontStyle
TopMargin BackColor
BottomMargin ForeColor
ProcessTilde
  • Resolution: The image resolution for Code 128 image. Default value is 72 DPI for screen display. If you want to output the barcode image with printer, please adjust this property according to your printer resolution.
  • ShowCheckSumChar: Code 128 is self-checking linear barcode symbol, but an obligatory checksum character is required by the ISO / IEC specification. It will be automatically encoded into Code 128 barcode image, and you can set this value to false to hide it.
  • ShowText: This is a Boolean value. You can set this value to false to hide the human readable data text under the generated Code 128 bar code image.
Draw Code 128 on Image & Document in C# Code
Generate Code 128 on image and document with mature C#.NET example code. All the properties above are included in the sample code here. Please make any change to these properties if necessary.
// invoke this only once at the beginning of your code
WorkRegistry.Reset();

// create REImage on which you want to draw the barcode
REImage reImage = new REImage("c:/Sample.png");

Linear barcode = new Linear();// create a barcode
barcode.Type = BarcodeType.CODE128;// select barcode type
barcode.Data = "123456789";// set barcode data

// Code 128 barcode size related
barcode.X = 1.0F;// set x
barcode.Y = 60.0F;// set y
barcode.BarcodeHeight = 60;
barcode.BarcodeWidth = 0;
barcode.BottomMargin = 0;
barcode.LeftMargin = 0;
barcode.RightMargin = 0;
barcode.BarAlignment = AlignmentHori.Left;
barcode.Resolution = 96;// set resolution
barcode.Rotate = Rotate.Rotate0;// set rotation
barcode.ShowCheckSumChar = false;
barcode.UOM = RasterEdge.Imaging.Barcode.Creator.UnitOfMeasure.PIXEL;

// Code 128 colors
barcode.BackColor = System.Drawing.Color.White;
barcode.ForeColor = System.Drawing.Color.Black;

// Code 128 font style
barcode.TextFont = new Font("Arial", 9f, FontStyle.Regular);
barcode.TextColor = System.Drawing.Color.Black;
barcode.TextMargin = 6;
barcode.ShowText = true;

// Code 128 special
barcode.ProcessTilde = false;

barcode.DrawBarcode(reImage, 0, 0);// draw barcode on REImage with location x and y

reImage.Save(ImageType.PNG, @"c:/barcode.png");


Recommend this to Google+