C# Code 128 Generator Library
How to generate Code 128 barcode image in PDF, TIFF, Word files in C#.NET ASP.NET, Windows application


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





In this C# tutorial, you will learn how to create a Code 128 barcode images using C# in ASP.NET MVC Web, Windows applications.

  • Generate high quality Code 128 barcode images
  • Advanced barcode options for size, color, barcode encoding
  • Print Code 128 in PNG, JPG, GIF, Bitmap raster images
  • Create Code 128 in PDF, TIFF, Office Word, Excel, PowerPoint files

How to create a Code 128 in PNG, JPEG, PDF, Tiff, Word file using C#

  1. Download XImage.Barcode Generator C# library
  2. Install C# library to create Code 128 barcodes
  3. Step by Step Tutorial














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.






Related .net document control helps:
asp.net document viewer control: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
asp.net edit pdf page: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net dicom viewer: ASP.NET Dicom Document Viewer Control: view, annotate dicom imaging files online in ASP.NET
asp.net tiff viewer control: ASP.NET Tiff Viewer: view, annotate multipage Tiff images in ASP.NET MVC, WebForms using C# Control
asp.net open word document in browser: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
asp.net image viewer zoom: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net edit pdf image control: ASP.NET PDF Image Edit Control: online insert, edit PDF images in C#



Detailed features are listed below:

  • 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






Code 128 Characters Encoding in C#


Code 128 Encode Character Set

Code 128 barcode encodes the following characters

  • All 128 Full ASCII characters
  • Extended ASCII characters
  • 4 non-data function characters
  • 4 code set selection characters
  • 3 Start characters and 1 Stop character



Code 128 Code Set

Code 128 barcode has three unique data character code sets. Each code set includes a subset of the full ASCII character set together with various special characters.

  • Code Sets A
  • Code Sets B
  • Code Sets C



Code 128 Special Characters

Code 128 has four Function Characters (FNC), four Code Set selection characters, three Start characters and one Stop character.

The Function Characters 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)



Code 128 Check Digit

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

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







How to calculate Code 128 barcode size (image width and height) using C#.NET


Using C# Code 128 generator, you can change the Code 128 barcode dimension size through the following barcode properties:

  • 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.









How to generate GS1-128 using C#.net


Code 128 barcode symbology is a valid data carrier for GS1 data. To create GS1 data in Code 128, please view How to generate GS1-128 barcode in C#?







List of C# Sample Codes




How to create a Code 128 barcode PNG image using C#.NET


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!

Below are the steps and C# sample source code to create a Code 128 barcode png image using C#.NET.

  1. Create a new Linear barcode object
  2. Set barcode type as "CODE128"
  3. Set Code 128 encoding data "Code 128".
  4. Set Code 128 barcode size related properties "AutoResize", "UOM", "BarcodeWidth", "BarcodeHeight", "Resolution", margins
  5. Print Code 128 barcode to a Bitmap object
  6. Save the bitmap object to a PNG image file




            RasterEdge.XImage.BarcodeCreator.Linear code128 = new RasterEdge.XImage.BarcodeCreator.Linear();

            code128.Type = RasterEdge.XImage.BarcodeCreator.BarcodeType.CODE128;
            code128.Data = "Code 128";

            //  Set barcode size to 3 inch x 1 inch
            code128.AutoResize = true;
            code128.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            code128.BarcodeWidth = 3F;
            code128.BarcodeHeight = 1F;
            //  Set image resolution to 300 dpi.
            code128.Resolution = 300;

            //  Set all margins to 0
            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;

            Bitmap code128Bitmap = code128.ToImage();
            code128Bitmap.Save(@"W:\Projects\Test-Output\RasterEdge.com\barcode-code128.png");






How to create a Code 128 barcode in PDF file using C#.NET


Below are the steps and C# sample source code to create a Code 128 barcode in an existing PDF file using C#.NET.

  1. Create a new Linear barcode object
  2. Set barcode type as "CODE128"
  3. Set Code 128 encoding data "Code 128".
  4. Set Code 128 barcode size related properties "AutoResize", "UOM", "BarcodeWidth", "BarcodeHeight", "Resolution", margins
  5. Create a new PDFDocument from an existing PDF file
  6. Get a new PDFPage object from the first page of the PDF document
  7. Generate and paint Code 128 barcode on the PDFPage object
  8. Save the PDF file



            RasterEdge.XImage.BarcodeCreator.Linear code128 = new RasterEdge.XImage.BarcodeCreator.Linear();

            code128.Type = RasterEdge.XImage.BarcodeCreator.BarcodeType.CODE128;
            code128.Data = "Code 128";

            //  Set barcode size to 3 inch x 1 inch
            code128.AutoResize = true;
            code128.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            code128.BarcodeWidth = 1F;
            code128.BarcodeHeight = 0.3F;
            //  Set image resolution to 300 dpi.
            code128.Resolution = 300;

            //  Set all margins to 0
            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\XDoc.PDF Overview.pdf";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-code128-pdf.pdf";

            PDFDocument doc = new PDFDocument(inputFilePath);
            //  Draw the barcode at position (100, 200) in pixels on the 1st page.
            PDFPage page = (PDFPage)doc.GetPage(0);
            code128.DrawBarcode(page, 100, 200);

            doc.Save(outputFilePath);






How to generate a Code 128 barcode in multipage Tiff image using C#.NET


Below are the steps and C# sample source code to generate and paint a Code 128 barcode in an existing multipage tiff image file using C#.NET.

  1. Create a new Linear barcode object
  2. Set barcode type as "CODE128"
  3. Set Code 128 encoding data "Code 128".
  4. Set Code 128 barcode size related properties "AutoResize", "UOM", "BarcodeWidth", "BarcodeHeight", "Resolution", margins
  5. Create a new TIFFDocument from an existing TIFF image file
  6. Get a new BasePage object from the first page of the TIFF document
  7. Generate and paint Code 128 barcode on the BasePage object
  8. Save the TIFF image



            RasterEdge.XImage.BarcodeCreator.Linear code128 = new RasterEdge.XImage.BarcodeCreator.Linear();

            code128.Type = RasterEdge.XImage.BarcodeCreator.BarcodeType.CODE128;
            code128.Data = "Code 128";

            //  Set barcode size to 3 inch x 1 inch
            code128.AutoResize = true;
            code128.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            code128.BarcodeWidth = 1F;
            code128.BarcodeHeight = 0.3F;
            //  Set image resolution to 300 dpi.
            code128.Resolution = 300;

            //  Set all margins to 0
            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\XDoc.PDF Overview.tiff";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-code128-tiff.tiff";

            TIFFDocument tiffDoc = new TIFFDocument(inputFilePath);

            //  Draw the barcode at position (100, 200) in pixels on the 1st page.
            BasePage page = tiffDoc.GetPage(0);
            code128.DrawBarcode(page, 100, 200);

            tiffDoc.Save(outputFilePath);






How to create a Code 128 barcode image in Office Word, Excel, PowerPoint document without interop using C#.NET


Below are the steps and C# sample source code to generate and paint a Code 128 barcode in an existing multipage tiff image file using C#.NET.

  1. Create a new Linear barcode object
  2. Set barcode type as "CODE128"
  3. Set Code 128 encoding data "Code 128".
  4. Set Code 128 barcode size related properties "AutoResize", "UOM", "BarcodeWidth", "BarcodeHeight", "Resolution", margins
  5. Create a new DOCXDocument from an existing Word docx file
  6. Get a new BasePage object from the first page of the Word document
  7. Generate and paint Code 128 barcode on a REImage object
  8. Add, insert the REImage object to the first page of the Word document
  9. Save the Word document



            RasterEdge.XImage.BarcodeCreator.Linear code128 = new RasterEdge.XImage.BarcodeCreator.Linear();

            code128.Type = RasterEdge.XImage.BarcodeCreator.BarcodeType.CODE128;
            code128.Data = "Code 128";

            //  Set barcode size to 3 inch x 1 inch
            code128.AutoResize = true;
            code128.UOM = RasterEdge.XImage.BarcodeCreator.UnitOfMeasure.INCH;
            code128.BarcodeWidth = 1F;
            code128.BarcodeHeight = 0.3F;
            //  Set image resolution to 300 dpi.
            code128.Resolution = 300;

            //  Set all margins to 0
            code128.LeftMargin = 0;
            code128.RightMargin = 0;
            code128.TopMargin = 0;
            code128.BottomMargin = 0;

            String inputFilePath = @"W:\Projects\Test-Files\word-empty.docx";
            String outputFilePath = @"W:\Projects\Test-Output\RasterEdge.com\barcode-code128-word.docx";

            DOCXDocument doc = new DOCXDocument(inputFilePath);

            //  Draw the barcode at position (100, 200) in pixels on the 1st page.
            BasePage page = doc.GetPage(0);

            REImage image = new REImage(code128.ToImage());
            page.AddImage(image, new PointF(100F, 200F));

            doc.Save(outputFilePath);