Drawing Barcode using OfficeComponent PDF

This topic introduces to the Barcode feature of the library. We also explain what Barcode is, its history and the barcode types.

What is Barcode?

  • Barcodes are representations of information in visible forms on the surface of products and goods that are machine-readable. Originally, Barcodes stored data according to the width of the lines printed in parallel. On the other hand, people also need to care about the space between these lines. Still, today they are also published in the form of points, in concentric circles, or people may hide them in the pictures. Barcodes can be read by optical scanning devices called Barcode Readers or scanned from images by specialized software.
  • The content of the Barcodes is information about the product, such as the country of registration of the Barcodes, the name of the enterprise, the lot, registration quality standards, information about the product size, place of inspection, etc.

The history of Barcode

  • The idea of a Barcodes was developed by Norman Joseph Woodland and Bernard Silver. In 1948, when they were students at Drexel University, they developed this idea after learning about the desire of a president of a food company to test automatically. One of the first ideas was to use Morse code to print wide or narrow vertical lines. They then switched to using the "black spot" format of Barcodes with concentric circles. They sent to the US patent office 2,612,994, October 20, 1949, Classifying Apparatus and Method (Equipment and classification methods) for a patent. The release of the patent was on October 7, 1952.
  • The first Barcodes Reader was designed and built by Woodland (then working for IBM) and Silver in 1952. It consisted of a 500W filament lamp and a photonic vacuum tube manufactured by Barcodes for audio films (it is for optical printing on film). But in fact, this device is not feasible: to get the current measured by an oscilloscope, the 500W lamp almost burned the paper with their first Barcodes sample. It has not been mass-produced. In 1962, they sold the patent to Philips, then Philips sold it to RCA. The invention of the laser in 1960 made bar code readers less expensive, and the development of a semiconductor circuit (IC) made it possible to decode signals received from Barcodes with real meaning.
  • In 1972, the Kroger store in Cincinnati experimented with using a black dot Barcodes reader, with the help of RCA. Unfortunately, the black-point Barcodes were very blurry when printing, and the experiment did not yield any significant success. At the same time, Woodland at IBM developed the linear Barcodes, which was accepted on April 3, 1973, as a Universal Product Code (UPC). In June 1974, the first sold retail product (a 10-pack of Wrigley's Juicy Fruit gum) used a Barcodes reader at Marsh Supermarket in Troy, Ohio. (This package of chewing gum is now in the US National Museum in the Smithsonian.) In 1992, President George H. W. Bush awarded Woodland the National Technology Medal Award.

Methods of symbolic expression

  • The conversion between message information and a Barcodes symbol is called a symbolic expression. The encoded parameters are from specific numbers/letters of the message, possible signs of the beginning or end of the bars. Spaces, the size of the calm area before and after Barcodes, as well as checksum calculations, are required.
  • The processes of the linear symbolic representation can be classified mainly by two properties:
  • Continuous or Discrete: Characters in an emblematic symbol are contiguous, with one character ending in space and the next starting with a line, or vice versa. Characters in discrete symbolic representations begin and end with a line; we ignore space between characters, as long as it is wide enough for the reader to treat the code as an end.
  • Two or more line widths: The lines and gaps in the symbolic representation of two widths are wide or narrow. How many times the line is more extensive than the thin line has no significant value in character recognition (usually the width of the line is 2-3 times the width of the narrow line). The lines and spaces in a symbol representing multiple widths are multiples of the necessary width called the module; Most of these Barcodes use four widths, which are 1, 2, 3, and 4 modules, respectively.
  • The cluster Barcodes contain linear bar codes of the same type but are repeated vertically in multiple rows. There are many types of 2D Barcodes. Most are code matrices, which are a collection of point or square sample modules distributed over the sample grid. 2D Barcodes may also have different types of visibility. Along with concentric circle patterns, there are also some 2D Barcodes that use steganography by hiding arrays of various modules of size or shape in specific images (for example, as of DataGlyph Barcodes).

Classify

  • Types of one-dimensional barcodes (1D)
  • UPC code
  • EAN code
  • Barcode 39
  • CODE 128
  • ITF barcode
  • Code and bar code 93
  • CODABAR
  • GS1 barcode
  • MSI PLESSEY
  • Types of 2-dimensional barcodes (2D)
  • QR CODE
  • DATAMATRIX barcode
  • Barcode PDF417
  • AZTEC

In short

  • Barcodes is a sequence of characters that can be numbers or digits. By definition, Barcodes are methods of storing and transmitting information with a specific type of symbol. This symbol is consisting of a combination of spaces and lines to represent letters, symbols, and numbers.
  • If the naked eye looks at a Barcodes, you can hardly tell what it is. But it is the changes inline widths and spaces that will represent numerical or numerical information in a machine-readable form.
  • The reading section for users to identify product information is a number. When looking at this sequence, one will know the origin of the product through the code convention for countries around the world of the GS1 Organization.

Uses of Barcode

  • Barcodes are like ID cards of goods. Through Barcodes, we can know precisely the origin of products. Depending on the country and region, bar code regulations will vary. The Barcodes of a commodity will consist of two parts. The first part is the identification number of the goods for human identification. The second part is the Barcodes for the badge by the scanners. Depending on the amount of information, the type of data encoded, and the purpose of use, we divide Barcode into many models. The most popular ones are UPC, EAN, Code 39, etc.

Problem

  • As mentioned above, Barcodes has become an indispensable thing in many social aspects. It represents transparency when it is considered an ID for anything it can present. Therefore, the recording, displaying, and performing Barcodes have become an indispensable aspect for text editors. Best of all, when you need to work with different types of products, even products on sale, whether it's Word or PDF, drawing these Barcodes is a must.
  • However, it is hard to find a tool that can quickly support the Barcodes drawing. All you can think about right now is just taking photos of each Barcodes, classifying, and presenting them on documents. What a troublesome process that is not worth it.
  • Introducing PDF Office Component, a mighty library for .NET, allowing you to integrate the Barcodes presentation feature right on your PDF document.

Types of Barcode that can be encoded

  • Codabar
  • Code 11
  • Code32
  • Code39
  • Code39Ext
  • Code93
  • Code93 Extended
  • Code128 A
  • Code128 B
  • Code128 C
  • GS1Code128
  • UPC-A
  • UPC-A
  • 2D QR Code
  • 2D Datamatrix

How to use

  • First, please make sure you have installed our PDF package. The following example takes advantage of the PDF barcode classes to generate barcode in a document:
  • C# Version:
using OfficeComponent.Pdf;
using OfficeComponent.Pdf.Graphics;
using OfficeComponent.Pdf.Graphics.Barcodes;
  • VB Version:
Imports OfficeComponent.Pdf
Imports OfficeComponent.Pdf.Graphics
Imports OfficeComponent.Pdf.Graphics.Barcodes
  • Next, create a PDF document object.
  • C# Version: PdfDocument document = new PdfDocument();
  • VB Version: Dim document As New PdfDocument()
  • Add some new pages to the document:
  • C# Version: PdfPage page = document.Pages.Add();
  • VB Version: Dim page As PdfPage = document.Pages.Add()
  • You will need to the format for your document layout:
  • C# Version:
// Create Pdf graphics for the page
PdfGraphics g = page.Graphics;

// Create a solid brush
PdfBrush brush = new PdfSolidBrush(Color.Black);
const float fontSize = 15f;

// Set the font
PdfFont headFont = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize, PdfFontStyle.Bold);
  • VB Version:
' Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics

' Create a solid brush
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
Const fontSize As Single = 15F
' Set the font
Dim headFont As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, fontSize, PdfFontStyle.Bold)
  • Drawing Barcode is now easy by taking advantage of the Pdf + type + Barcode class and the DrawString methods. You will need to replace the phase-type with your desired Barcode type. For example, Code11 would be PdfCode11Barcode

The Snippet below will demonstrate how to use the methods of PDF Office Component:

  • C# Version:
// Create a new instance of PdfDocument class.
PdfDocument document = new PdfDocument();
// Add a page
PdfPage page = document.Pages.Add();
// Create Pdf graphics for the page
PdfGraphics g = page.Graphics;
// Create a solid brush
PdfBrush brush = new PdfSolidBrush(Color.Black);
const float fontSize = 15f;
// Set the font
PdfFont headFont = new PdfStandardFont(PdfFontFamily.Helvetica, fontSize, PdfFontStyle.Bold);

// Drawing header text
g.DrawString("1D BarCodes", headFont, brush, new PointF(210, 10));

PdfFont font = new PdfStandardFont(PdfFontFamily.Courier, 10, PdfFontStyle.Italic);

PdfPen pen = new PdfPen(PdfBrushes.DarkGray, 0.5f);

PdfStringFormat format = new PdfStringFormat();
format.WordWrap = PdfWordWrap.Word;

float clientWidth = page.GetClientSize().Width;
float left = 10.0f;
int top = 40;
float textXPos = 200.0f;

#region Codabar
int y = top + 20;
// Drawing CodaBarcode
PdfCodabarBarcode codabar = new PdfCodabarBarcode();
// Setting height of the barcode
codabar.BarHeight = 45;
codabar.Text = "0123";
// Printing barcode on to the Pdf.
codabar.Draw(page, new PointF(left, y));

g.DrawString("Type : Codabar", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : A,B,C,D,0-9,-$,:,/,a dot(.),+ ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

#region Code11Barcode
y += 100;
// Drawing Code11  barcode
PdfCode11Barcode barcode11 = new PdfCode11Barcode();
// Setting height of the barcode
barcode11.BarHeight = 45;
barcode11.Text = "012345678";
barcode11.EncodeStartStopSymbols = true;
// Printing barcode on to the Pdf.
barcode11.Draw(page, new PointF(left, y));

g.DrawString("Type : Code 11", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 0-9, a dash(-) ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

#region Code32
y += 100;
PdfCode32Barcode code32 = new PdfCode32Barcode();

code32.Font = font;

// Setting height of the barcode
code32.BarHeight = 45;
code32.Text = "01234567";
code32.TextDisplayLocation = TextLocation.Bottom;
code32.EnableCheckDigit = true;
code32.ShowCheckDigit = true;

// Printing barcode on to the Pdf.
code32.Draw(page, new PointF(left, y));

g.DrawString("Type : Code32", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));

#endregion

#region Code39
y += 100;
// Drawing Code39 barcode
PdfCode39Barcode barcode = new PdfCode39Barcode();
// Setting height of the barcode
barcode.BarHeight = 45;
barcode.Text = "CODE39$";
// Printing barcode on to the Pdf.
barcode.Draw(page, new PointF(left, y));

g.DrawString("Type : Code39", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 0-9, A-Z,a dash(-),a dot(.),$,/,+,%, SPACE", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

#region Code39Extended
y += 100;
// Drawing Code39Extended barcode
PdfCode39ExtendedBarcode barcodeExt = new PdfCode39ExtendedBarcode();
// Setting height of the barcode
barcodeExt.BarHeight = 45;
barcodeExt.Text = "CODE39Ext";
// Printing barcode on to the Pdf.
barcodeExt.Draw(page, new PointF(left, y));

g.DrawString("Type : Code39Ext", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 0-9 A-Z a-z ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

#region Code93

PdfCode93Barcode code93 = new PdfCode93Barcode();
y += 100;
// Setting height of the barcode
code93.BarHeight = 45;
code93.Text = "ABC 123456789";
// Printing barcode on to the Pdf.
code93.Draw(page, new PointF(left, y));


g.DrawString("Type : Code93", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - . $ / + % SPACE ", font, PdfBrushes.Black, new RectangleF(200, y + 25, 300, 200), format);

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

#region Code93Extended
y += 100;
PdfCode93ExtendedBarcode code93Ext = new PdfCode93ExtendedBarcode();

// Setting height of the barcode
code93Ext.BarHeight = 45;
code93Ext.EncodeStartStopSymbols = true;
code93Ext.Text = "(abc) 123456789";

// Printing barcode on to the Pdf.
code93Ext.Draw(page, new PointF(left, y));

g = page.Graphics;
g.DrawString("Type : Code93 Extended", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : All 128 ASCII characters ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));
#endregion

page = document.Pages.Add();
g = page.Graphics;

#region Code128
y = top;
PdfCode128ABarcode barcode128A = new PdfCode128ABarcode();
// Setting height of the barcode
barcode128A.BarHeight = 45;
barcode128A.Text = "ABCD 12345";
barcode128A.EnableCheckDigit = true;
barcode128A.EncodeStartStopSymbols = true;
barcode128A.ShowCheckDigit = true;

// Printing barcode on to the Pdf.
barcode128A.Draw(page, new PointF(left, y));

g.DrawString("Type : Code128 A", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : NUL (0x00) SOH (0x01) STX (0x02) ETX (0x03) EOT (0x04) ENQ (0x05) ACK (0x06) BEL (0x07) BS (0x08) HT (0x09) LF (0x0A) VT (0x0B) FF (0x0C) CR (0x0D) SO (0x0E) SI (0x0F) DLE (0x10) DC1 (0x11) DC2 (0x12) DC3 (0x13) DC4 (0x14) NAK (0x15) SYN (0x16) ETB (0x17) CAN (0x18) EM (0x19) SUB (0x1A) ESC (0x1B) FS (0x1C) GS (0x1D) RS (0x1E) US (0x1F) SPACE (0x20) \" ! # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _  ", font, PdfBrushes.Black, new RectangleF(200, y + 25, 300, 200), format);

g.DrawLine(pen, new PointF(0, y + 170), new PointF(clientWidth, y + 170));

y += 200;
PdfCode128BBarcode barcode128B = new PdfCode128BBarcode();
// Setting height of the barcode
barcode128B.BarHeight = 45;
barcode128B.Text = "12345 abcd";
barcode128B.EnableCheckDigit = true;
barcode128B.EncodeStartStopSymbols = true;
barcode128B.ShowCheckDigit = true;

// Printing barcode on to the Pdf.
barcode128B.Draw(page, new PointF(left, y));

g.DrawString("Type : Code128 B", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : SPACE (0x20) !  \" # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ DEL (\x7F)  ", font, PdfBrushes.Black, new RectangleF(textXPos, y + 25, 300, 200), format);

g.DrawLine(pen, new PointF(0, y + 100), new PointF(clientWidth, y + 100));

y += 130;
PdfCode128CBarcode barcode128C = new PdfCode128CBarcode();
// Setting height of the barcode
barcode128C.BarHeight = 45;
barcode128C.Text = "001122334455";
barcode128C.EnableCheckDigit = true;
barcode128C.EncodeStartStopSymbols = true;
barcode128C.ShowCheckDigit = true;

// Printing barcode on to the Pdf.
barcode128C.Draw(page, new PointF(left, y));

g.DrawString("Type : Code128 C", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 0 1 2 3 4 5 6 7 8 9 ", font, PdfBrushes.Black, new PointF(textXPos, y + 25));

g.DrawLine(pen, new PointF(0, y + 70), new PointF(clientWidth, y + 70));

#endregion


#region GS1Code128

y += 100;

PdfGS1Code128Barcode gs1Code128 = new PdfGS1Code128Barcode();
gs1Code128.Text = "(01)12345678901234";
//Drawing in PDF page
gs1Code128.Draw(page, new PointF(left, y));
page.Graphics.DrawString("Type : GS1Code128", font, brush, new PointF(textXPos, y + 5));
page.Graphics.DrawString("Allowed Characters : SPACE (0x20)  0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  a b c d e f g h i j k l m n o p q r s t u v w x y z", font, brush,
    new RectangleF(textXPos, y + 25, 300, 200));

int liney = y + 25 + 100;
g.DrawLine(pen, new PointF(0, liney), new PointF(clientWidth, liney));

#endregion

#region UPC-A

y += 150;

// Drawing UPC-A barcode
PdfCodeUpcBarcode upcBarcode = new PdfCodeUpcBarcode();

// Setting height of the barcode
upcBarcode.BarHeight = 45;
upcBarcode.Text = "01234567890";

//Printing barcode on to the Pdf.
upcBarcode.Draw(page, new PointF(left, y));

g.DrawString("Type : UPC-A", font, brush, new PointF(textXPos, y + 5));
g.DrawString("Allowed Characters : 0-9", font, brush, new PointF(textXPos, y + 25));



#endregion


page = document.Pages.Add();
g = page.Graphics;
y = top + 20;

// Drawing header text
g.DrawString("2D BarCodes", headFont, brush, new PointF(210, 10));

#region QR Barcode


PdfQRBarcode qrBarcode = new PdfQRBarcode();

// Sets the Input mode to Binary mode
qrBarcode.InputMode = InputMode.BinaryMode;

// Automatically select the Version
qrBarcode.Version = QRCodeVersion.Auto;

// Set the Error correction level to high
qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High;

string encodedData = "QR Barcode Demo";

// Set dimension for each block
qrBarcode.XDimension = 4;
qrBarcode.Text = encodedData;

// Draw the QR barcode
qrBarcode.Draw(page, new PointF(left, y));

g.DrawString("Type : 2D QR Code", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Input Type : Eight Bit Binary", font, PdfBrushes.Black, new PointF(textXPos, y + 25));
g.DrawString("Encoded Data : " + encodedData, font, PdfBrushes.Black, new PointF(textXPos, y + 45));

g.DrawLine(pen, new PointF(0, y + 150), new PointF(clientWidth, y + 150));

#endregion

#region Datamatrix

y += 170;

encodedData = "OfficeComponent PDF";
PdfDataMatrixBarcode dataMatrixBarcode = new PdfDataMatrixBarcode(encodedData);

// Set dimension for each block
dataMatrixBarcode.XDimension = 4;

// Draw the barcode
dataMatrixBarcode.Draw(page, new PointF(left, y));

g.DrawString("Type : 2D Datamatrix", font, PdfBrushes.Black, new PointF(textXPos, y + 5));
g.DrawString("Symbol Type : Square", font, brush, new PointF(textXPos, y + 25));
g.DrawString("Encoded Data : " + encodedData, font, brush, new PointF(textXPos, y + 45));

string text = "TYPE 3523 - ETWS/N FE- SDFHW 06/08";

dataMatrixBarcode = new PdfDataMatrixBarcode(text);

y += 100;
// rectangular matrix
dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48;

dataMatrixBarcode.XDimension = 4;

dataMatrixBarcode.Draw(page, new PointF(left, y));

g.DrawString("Symbol Type : Rectangle", font, brush, new PointF(textXPos + 20, y + 5));
g.DrawString("Encoded Data : " + text, font, brush, new PointF(textXPos + 20, y + 25));

g.DrawLine(pen, new PointF(0, y + 160), new PointF(clientWidth, y + 160));


#endregion


// Save and close the document.
var outputPath = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + ".pdf");
document.Save(outputPath);
document.Close(true);

return outputPath;
  • VB Version:
'Create a new instance of PdfDocument class.
Dim document As New PdfDocument()
' Add a page
Dim page As PdfPage = document.Pages.Add()

' Create Pdf graphics for the page
Dim g As PdfGraphics = page.Graphics

' Create a solid brush
Dim brush As PdfBrush = New PdfSolidBrush(Color.Black)
Const fontSize As Single = 15F
' Set the font
Dim headFont As PdfFont = New PdfStandardFont(PdfFontFamily.Helvetica, fontSize, PdfFontStyle.Bold)

' Drawing header text
g.DrawString("1D BarCodes", headFont, brush, New PointF(210, 10))

Dim font As PdfFont = New PdfStandardFont(PdfFontFamily.Courier, 10, PdfFontStyle.Italic)

Dim pen As New PdfPen(PdfBrushes.DarkGray, 0.5F)

Dim format As New PdfStringFormat()
format.WordWrap = PdfWordWrap.Word

Dim clientWidth As Single = page.GetClientSize().Width
Dim left As Single = 10.0F
Dim top As Integer = 40
Dim textXPos As Single = 200.0F

#Region "Codabar"
Dim y As Integer = top + 20
' Drawing CodaBarcode
Dim codabar As New PdfCodabarBarcode()
' Setting height of the barcode
codabar.BarHeight = 45
codabar.Text = "0123"
' Printing barcode on to the Pdf.
codabar.Draw(page, New PointF(left, y))

g.DrawString("Type : Codabar", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : A,B,C,D,0-9,-$,:,/,a dot(.),+ ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

#Region "Code11Barcode"
y += 100
' Drawing Code11  barcode
Dim barcode11 As New PdfCode11Barcode()
' Setting height of the barcode
barcode11.BarHeight = 45
barcode11.Text = "012345678"
barcode11.EncodeStartStopSymbols = True
' Printing barcode on to the Pdf.
barcode11.Draw(page, New PointF(left, y))

g.DrawString("Type : Code 11", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 0-9, a dash(-) ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

#Region "Code32"
y += 100
Dim code32 As New PdfCode32Barcode()

code32.Font = font

' Setting height of the barcode
code32.BarHeight = 45
code32.Text = "01234567"
code32.TextDisplayLocation = TextLocation.Bottom
code32.EnableCheckDigit = True
code32.ShowCheckDigit = True

' Printing barcode on to the Pdf.
code32.Draw(page, New PointF(left, y))

g.DrawString("Type : Code32", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))

#End Region

#Region "Code39"
y += 100
' Drawing Code39 barcode
Dim barcode As New PdfCode39Barcode()
' Setting height of the barcode
barcode.BarHeight = 45
barcode.Text = "CODE39$"
' Printing barcode on to the Pdf.
barcode.Draw(page, New PointF(left, y))

g.DrawString("Type : Code39", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 0-9, A-Z,a dash(-),a dot(.),$,/,+,%, SPACE", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

#Region "Code39Extended"
y += 100
' Drawing Code39Extended barcode
Dim barcodeExt As New PdfCode39ExtendedBarcode()
' Setting height of the barcode
barcodeExt.BarHeight = 45
barcodeExt.Text = "CODE39Ext"
' Printing barcode on to the Pdf.
barcodeExt.Draw(page, New PointF(left, y))

g.DrawString("Type : Code39Ext", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 0-9 A-Z a-z ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

#Region "Code93"

Dim code93 As New PdfCode93Barcode()
y += 100
' Setting height of the barcode
code93.BarHeight = 45
code93.Text = "ABC 123456789"
' Printing barcode on to the Pdf.
code93.Draw(page, New PointF(left, y))


g.DrawString("Type : Code93", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 1 2 3 4 5 6 7 8 9 0 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z - . $ / + % SPACE ", font, PdfBrushes.Black, New RectangleF(200, y + 25, 300, 200), format)

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

#Region "Code93Extended"
y += 100
Dim code93Ext As New PdfCode93ExtendedBarcode()

' Setting height of the barcode
code93Ext.BarHeight = 45
code93Ext.EncodeStartStopSymbols = True
code93Ext.Text = "(abc) 123456789"

' Printing barcode on to the Pdf.
code93Ext.Draw(page, New PointF(left, y))

g = page.Graphics
g.DrawString("Type : Code93 Extended", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : All 128 ASCII characters ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))
#End Region

page = document.Pages.Add()
g = page.Graphics

#Region "Code128"
y = top
Dim barcode128A As New PdfCode128ABarcode()
' Setting height of the barcode
barcode128A.BarHeight = 45
barcode128A.Text = "ABCD 12345"
barcode128A.EnableCheckDigit = True
barcode128A.EncodeStartStopSymbols = True
barcode128A.ShowCheckDigit = True

' Printing barcode on to the Pdf.
barcode128A.Draw(page, New PointF(left, y))

g.DrawString("Type : Code128 A", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : NUL (0x00) SOH (0x01) STX (0x02) ETX (0x03) EOT (0x04) ENQ (0x05) ACK (0x06) BEL (0x07) BS (0x08) HT (0x09) LF (0x0A) VT (0x0B) FF (0x0C) CR (0x0D) SO (0x0E) SI (0x0F) DLE (0x10) DC1 (0x11) DC2 (0x12) DC3 (0x13) DC4 (0x14) NAK (0x15) SYN (0x16) ETB (0x17) CAN (0x18) EM (0x19) SUB (0x1A) ESC (0x1B) FS (0x1C) GS (0x1D) RS (0x1E) US (0x1F) SPACE (0x20) "" ! # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _  ", font, PdfBrushes.Black, New RectangleF(200, y + 25, 300, 200), format)

g.DrawLine(pen, New PointF(0, y + 170), New PointF(clientWidth, y + 170))

y += 200
Dim barcode128B As New PdfCode128BBarcode()
' Setting height of the barcode
barcode128B.BarHeight = 45
barcode128B.Text = "12345 abcd"
barcode128B.EnableCheckDigit = True
barcode128B.EncodeStartStopSymbols = True
barcode128B.ShowCheckDigit = True

' Printing barcode on to the Pdf.
barcode128B.Draw(page, New PointF(left, y))

g.DrawString("Type : Code128 B", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : SPACE (0x20) !  "" # $ % & ' ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ / ]^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ DEL (" & ChrW(&H7F).ToString() & ")  ", font, PdfBrushes.Black, New RectangleF(textXPos, y + 25, 300, 200), format)

g.DrawLine(pen, New PointF(0, y + 100), New PointF(clientWidth, y + 100))

y += 130
Dim barcode128C As New PdfCode128CBarcode()
' Setting height of the barcode
barcode128C.BarHeight = 45
barcode128C.Text = "001122334455"
barcode128C.EnableCheckDigit = True
barcode128C.EncodeStartStopSymbols = True
barcode128C.ShowCheckDigit = True

' Printing barcode on to the Pdf.
barcode128C.Draw(page, New PointF(left, y))

g.DrawString("Type : Code128 C", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 0 1 2 3 4 5 6 7 8 9 ", font, PdfBrushes.Black, New PointF(textXPos, y + 25))

g.DrawLine(pen, New PointF(0, y + 70), New PointF(clientWidth, y + 70))

#End Region


#Region "GS1Code128"

y += 100

Dim gs1Code128 As New PdfGS1Code128Barcode()
gs1Code128.Text = "(01)12345678901234"
'Drawing in PDF page
gs1Code128.Draw(page, New PointF(left, y))
page.Graphics.DrawString("Type : GS1Code128", font, brush, New PointF(textXPos, y + 5))
page.Graphics.DrawString("Allowed Characters : SPACE (0x20)  0 1 2 3 4 5 6 7 8 9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  a b c d e f g h i j k l m n o p q r s t u v w x y z", font, brush, New RectangleF(textXPos, y + 25, 300, 200))

Dim liney As Integer = y + 25 + 100
g.DrawLine(pen, New PointF(0, liney), New PointF(clientWidth, liney))

#End Region

#Region "UPC-A"

y += 150

' Drawing UPC-A barcode
Dim upcBarcode As New PdfCodeUpcBarcode()

' Setting height of the barcode
upcBarcode.BarHeight = 45
upcBarcode.Text = "01234567890"

'Printing barcode on to the Pdf.
upcBarcode.Draw(page, New PointF(left, y))

g.DrawString("Type : UPC-A", font, brush, New PointF(textXPos, y + 5))
g.DrawString("Allowed Characters : 0-9", font, brush, New PointF(textXPos, y + 25))



#End Region


page = document.Pages.Add()
g = page.Graphics
y = top + 20

' Drawing header text
g.DrawString("2D BarCodes", headFont, brush, New PointF(210, 10))

#Region "QR Barcode"


Dim qrBarcode As New PdfQRBarcode()

' Sets the Input mode to Binary mode
qrBarcode.InputMode = InputMode.BinaryMode

' Automatically select the Version
qrBarcode.Version = QRCodeVersion.Auto

' Set the Error correction level to high
qrBarcode.ErrorCorrectionLevel = PdfErrorCorrectionLevel.High

Dim encodedData As String = "QR Barcode Demo"

' Set dimension for each block
qrBarcode.XDimension = 4
qrBarcode.Text = encodedData

' Draw the QR barcode
qrBarcode.Draw(page, New PointF(left, y))

g.DrawString("Type : 2D QR Code", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Input Type : Eight Bit Binary", font, PdfBrushes.Black, New PointF(textXPos, y + 25))
g.DrawString("Encoded Data : " & encodedData, font, PdfBrushes.Black, New PointF(textXPos, y + 45))

g.DrawLine(pen, New PointF(0, y + 150), New PointF(clientWidth, y + 150))
#End Region
#Region "Datamatrix"

y += 170

encodedData = "OfficeComponent PDF"
Dim dataMatrixBarcode As New PdfDataMatrixBarcode(encodedData)

' Set dimension for each block
dataMatrixBarcode.XDimension = 4

' Draw the barcode
dataMatrixBarcode.Draw(page, New PointF(left, y))

g.DrawString("Type : 2D Datamatrix", font, PdfBrushes.Black, New PointF(textXPos, y + 5))
g.DrawString("Symbol Type : Square", font, brush, New PointF(textXPos, y + 25))
g.DrawString("Encoded Data : " & encodedData, font, brush, New PointF(textXPos, y + 45))

Dim text As String = "TYPE 3523 - ETWS/N FE- SDFHW 06/08"

dataMatrixBarcode = New PdfDataMatrixBarcode(text)

y += 100
' rectangular matrix
dataMatrixBarcode.Size = PdfDataMatrixSize.Size16x48

dataMatrixBarcode.XDimension = 4

dataMatrixBarcode.Draw(page, New PointF(left, y))

g.DrawString("Symbol Type : Rectangle", font, brush, New PointF(textXPos + 20, y + 5))
g.DrawString("Encoded Data : " & text, font, brush, New PointF(textXPos + 20, y + 25))

g.DrawLine(pen, New PointF(0, y + 160), New PointF(clientWidth, y + 160))

#End Region


' Save and close the document.
Dim outputPath = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & ".pdf")
document.Save(outputPath)
document.Close(True)

Return outputPath

The full source code of this example is available in our PDF package.

A live demo for PDF Barcode is also available on our site. If you also need PDF functionality, check out our PDF online demos.

45-Day Money Back Guarantee

We will refund your full money in 45 days
if you are not satisfied with our products

Buy Now
You have successfully subcribed to our mailing list.
Dont miss out Get update on new articles and other opportunities Subscribe