Draw PDF Barcode in C#/VB.NET

PDF Barcode is an optical machine-readable representation of data that shows data about the object to which it attaches. It is universally used to automate supermarket checkout systems. This section will introduce a solution to draw PDF barcode via a .NET PDF component in C#, VB.NET.

Spire.PDF for .NET which implements rich capabilities to create, edit and manipulate PDF files on .NET enables you to not only to draw PDF barcode but also set the format of the PDF barcode in C#, VB.NET. By creating an instance of Spire.Pdf.Barcode.PdfCodaBar class, you can draw PDF barcode. After that, you can set barcode format and some properties such as text display location, color etc. Please see effect as below picture:

Draw Barcode in PDF

Here you can download Spire.PDF for .NET and install it on your system. Before viewing the key code, please do not forget to add Spire.Pdf reference in your project.

[C#]
           //draw Codabar
            PdfTextWidget text = new PdfTextWidget();
            text.Font = font1;
            text.Text = "Codabar:";
            PdfLayoutResult result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCodabarBarcode barcode1 = new PdfCodabarBarcode("00:12-3456/7890");
            barcode1.BarcodeToTextGapHeight = 1f;
            barcode1.EnableCheckDigit = true;
            barcode1.ShowCheckDigit = true;
            barcode1.TextDisplayLocation = TextLocation.Bottom;
            barcode1.TextColor = Color.Green;
            barcode1.Draw(page, new PointF(0, y));
            y = barcode1.Bounds.Bottom + 5;


            //draw Barcode
            text.Text = "Code123:";
            result = text.Draw(page, 0, y);
            page = result.Page;
            y = result.Bounds.Bottom + 2;

            PdfCode11Barcode barcode2 = new PdfCode11Barcode("123-4567890");
            barcode2.BarcodeToTextGapHeight = 1f;
            barcode2.TextDisplayLocation = TextLocation.Bottom;
            barcode2.TextColor = Color.OrangeRed;
            barcode2.Draw(page, new PointF(0, y));
            y = barcode2.Bounds.Bottom + 5;
[VB.NET]
'draw Codabar
Dim text As New PdfTextWidget()
text.Font = font1
text.Text = "Codabar:"
Dim result As PdfLayoutResult = text.Draw(page, 0, y)
page = result.Page
y = result.Bounds.Bottom + 2

Dim barcode1 As New PdfCodabarBarcode("00:12-3456/7890")
barcode1.BarcodeToTextGapHeight = 1F
barcode1.EnableCheckDigit = True
barcode1.ShowCheckDigit = True
barcode1.TextDisplayLocation = TextLocation.Bottom
barcode1.TextColor = Color.Green
barcode1.Draw(page, New PointF(0, y))
y = barcode1.Bounds.Bottom + 5

'draw Barcode
text.Text = "Code123:"
result = text.Draw(page, 0, y)
page = result.Page
y = result.Bounds.Bottom + 2

Dim barcode2 As New PdfCode11Barcode("123-4567890")
barcode2.BarcodeToTextGapHeight = 1F
barcode2.TextDisplayLocation = TextLocation.Bottom
barcode2.TextColor = Color.OrangeRed
barcode2.Draw(page, New PointF(0, y))
y = barcode2.Bounds.Bottom + 5

Spire.PDF for .NET is a professional PDF component which enables you to perform a wide range of PDF tasks in your .NET applications such as create, read, edit, write etc