C#: Online Guide
How To: Barcode Generator
Code 128
Code 128
  |  
Home ›› XImage.Barcode Generator ›› C# Barcode Generator: Code 128

C# Imaging - C# Code 128 Generation Guide


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




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.


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




C# Code for Customizing Code 128 Barcode Generation



You can easily generator Code 128 barcode and save it  to image files/object using this C#.NET barcode generator control. The following steps will show how to create a Code 128 type barcode encoding numeric data text "123456789" into the image object with XImage.Barcode.Creator.


Add References


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XImage.BarcodeCreator.dll


Using Namespaces


  using RasterEdge.XImage.BarcodeCreator;


Please copy the sample code as follow to generator a Code 128 barcode.




private static Linear CreateBarcode()
        {
            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.BarcodeWidth = 200;
            barcode.BarcodeHeight = 200;
            barcode.AutoResize = true;

            return barcode;
        }





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!




private static void AddBarcodeToImage(Linear barcode)
        {
            REImage image = new REImage(inputDirectory + "Sample.png");
            barcode.DrawBarcode(image, 150F, 150F);
            image.Save(ImageType.PNG, outputDirectory + "Sample_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



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PDF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;



private static void AddBarcodeToPDF(Linear barcode)
        {
            PDFDocument docx = new PDFDocument(inputDirectory + "Sample.pdf");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pdf");
        }




Create Code 128 on Certain TIFF Document Page



Add References(Extra)


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.TIFF.dll


Using Namespace(Extra)


  RasterEdge.XDoc.TIFF;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToTIFF(Linear barcode)
        {
            TIFFDocument docx = new TIFFDocument(inputDirectory + "Sample.tif");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.tif");
        }




Create Code 128 on Microsoft Office Word Document



Add References(Extra)


  RasterEdge.XDoc.Word.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Word;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToWord(Linear barcode)
        {
            DOCXDocument docx = new DOCXDocument(inputDirectory + "Sample.docx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.docx");
        }




Create Code 128 on Microsoft Excel Document



Add References(Extra)


  RasterEdge.XDoc.Excel.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.Excel;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToExcel(Linear barcode)
        {
            XLSXDocument docx = new XLSXDocument(inputDirectory + "Sample.xlsx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.xlsx");
        }




Create Code 128 on Microsoft PowerPoint Document



Add References(Extra)


  RasterEdge.XDoc.PowerPoint.dll


  RasterEdge.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.Office.Inner.Common.dll


  RasterEdge.XDoc.Office.Inner..Office03.dll


Using Namespace(Extra)


  RasterEdge.XDoc.PowerPoint;


  RasterEdge.Imaging.Basic;


  RasterEdge.Imaging.Raster.Core;




private static void AddBarcodeToPowerPoint(Linear barcode)
        {
            PPTXDocument docx = new PPTXDocument(inputDirectory + "Sample.pptx");
            BasePage page = docx.GetPage(0);
            REImage image = new REImage(barcode.ToImage());
            page.AddImage(image, new PointF(100F, 100F));
            docx.Save(outputDirectory + "Sample_Barcode.pptx");
        }





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.




// 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");