This topic introduces to the Barcode feature of the library. We also explain what Barcode is, its history and the barcode types.
- 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.
- UPC code
- EAN code
- Barcode 39
- CODE 128
- ITF barcode
- Code and bar code 93
- CODABAR
- GS1 barcode
- MSI PLESSEY
- QR CODE
- DATAMATRIX barcode
- Barcode PDF417
- AZTEC
- 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
- C# Version:
PdfDocument document = new PdfDocument();
- VB Version:
Dim document As New PdfDocument()
- C# Version:
PdfPage page = document.Pages.Add();
- VB Version:
Dim page As PdfPage = document.Pages.Add()
- 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)
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.