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

C# Imaging - Postnet Barcode Creation Tutorial


C# Code for POSTNET Barcode Generation in .NET Imaging Project




C# Image - Postnet Barcode Generator Control Overview



This C#.NET Postnet barcode generator library allows developers and end users to easily draw and customize Postnet barcode on common image and document files, including PNG, BMP, GIF, JPEG, TIFF, PDF, Excel, PowerPoint and Microsoft Word. It also empowers C#.NET developers to specify the location of generated Postnet barcode in a target file.


Related .net document control helps:
asp.net mvc pdf editor using c#: ASP.NET MVC PDF Viewer & Editor: view, annotate, redact, edit PDF document in C# ASP.NET MVC
asp.net sharepoint document viewer open source: ASP.NET SharePoint Document Viewer: view, annotate, redact documents in SharePoint
c# asp.net image viewer: ASP.NET Image Viewer Control(MVC & WebForms): view, annotate, redact, convert image files in html, JQuery
asp.net edit pdf page using c#: ASP.NET PDF Pages Edit Control: add, remove, sort, replace PDF pages online using C#
asp.net pdf document viewer c#: ASP.NET PDF Document Viewer in C#: open, display, view, annotate, redact Adobe PDF files online in ASP.NET MVC & WebForm...
asp.net document viewer open source: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
asp.net edit pdf text using c#: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET


RasterEdge C#.NET Barcode Creator Add-on can be seamlessly combined with image processing and management system so that users are able to process and edit created barcode image in color, black and white or grayscale. Particular barcode image manipulation functions contain resizing, printing, saving and more.


Detailed features are listed below:


Advanced Postnet generating and barcode image processing control in C# class applications


Easy-to-use image decoder tool for opening target barcoding image quickly


Automatically calculate and add checksum digit to Postnet barcode in C#


Flexible Postnet barcode generating library for adjusting barcode value, like bar width and height


Barcode rotation solution for revolving created Postnet barcode image in C# code


Draw Postnet barcode on PDF, Word, Excel, PowerPoint or TIFF document page by using document barcode drawing APIs


Output barcode image to any designed route in your C#.NET project




C# Code for Customizing POSTNET Barcode Generation



You can easily generator POSTNET barcode and save it  to image files/object using this C#.NET barcode generator control. The following steps will show how to create a POSTNET type barcode encoding numeric data text "01234" 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


  System.Drawing.dll


Using Namespaces


  using System.Drawing;


  using RasterEdge.XImage.BarcodeCreator;


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.



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




private static Linear CreateBarcode()
        {
            Linear barcode = new Linear();// create a barcode
            barcode.Type = BarcodeType.POSTNET;// select barcode type
            barcode.Data = "01234";// 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;

            //convert barcode to a bitmap and save it to image file
            //Bitmap bmp = barcode.ToImage();
            //bmp.Save(@"C:\barcode.bmp");

            return barcode;
        }





C# Image - Create Postnet Barcode on Image Files



Using this C#.NET Postnet barcode generator library, you can generate & draw Postnet barcode on png, gif, jpeg and bmp image files. Besides, you can generate Postnet barcode at the specified location of source file.




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





C# Image - Create Postnet on Document Files



If you want to generate Postnet barcode on a single-page or multi-page document files in C#.NET application, like PDF, Word, Excel, PowerPoint and TIFF, this Postnet Barcode Creator Add-on of RasterEdge DocImage SDK for .NET is quite suitable.



Postnet Barcode Generation in PDF File



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




Postnet Barcode Drawing in Specific TIFF File 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");
        }




Postnet Barcode Creation in 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");
        }




Postnet Barcode Drawing on Excel Sheet



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




Postnet Barcode Writing on PowerPoint Slide



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





C# Imaging - Entire C# Code to Create Postnet Barcode



Following C# code contains all above mentioned barcode generating parameters and you can use it to generate a customized Postnet barcode on a png image file.




// 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.POSTNET;// select barcode type
barcode.Data = "01234";// set barcode data 

// POSTNET size settings
barcode.UOM = RasterEdge.Imaging.Barcode.Creator.UnitOfMeasure.PIXEL;
barcode.X = 2.0F;
barcode.Y = 80F;
barcode.BarcodeHeight = 120;
barcode.BarcodeWidth = 120;
barcode.BottomMargin = 20;
barcode.TopMargin = 20;
barcode.BottomMargin = 20;
barcode.LeftMargin = 20;
barcode.RightMargin = 20;
barcode.AutoResize = false;
barcode.BarAlignment = AlignmentHori.Center;

// POSTNET unique settings
barcode.ShortTallRatio = 0.4F;

// color related settings
barcode.BackColor = System.Drawing.Color.White;
barcode.ForeColor = System.Drawing.Color.Black;

// human-readable text related settings
barcode.ShowText = true;
barcode.TextFont = new Font("Arial", 9f, FontStyle.Regular);
barcode.TextMargin = 6F;
barcode.TextColor = System.Drawing.Color.Black;

// other related settings
barcode.Resolution = 96;
barcode.Rotate = Rotate.Rotate0;

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

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