Add barcodes to PDF

This article demonstrates how to add barcodes to a PDF document.

With PDFKit it is possible to add multiple types of barcodes to your PDF document, such as regular 128 bit barcodes, PDF barcodes and QR codes among others.

Pdf Create Barcodes 2

//create a new PDF and add a single page to it
Document doc = new Document();
Page page = new Page(PageSize.Letter);
doc.Pages.Add(page);

//create a new barcode shape and add it to the page
Code3of9BarcodeShape shape = new Code3of9BarcodeShape();
page.VisualOverlay.Add(shape);

//specify some members of the barcode shape
shape.Location = TextLocation.BelowEmbedded;
shape.Transform = new TranslateTransform(50, 600);
shape.Width = 200;
shape.Height = 50;
shape.Data = "123456789";

//create a new qr code shape and add it to the page
QRBarcodeShape qr = new QRBarcodeShape();
page.VisualOverlay.Add(qr);

//specify some members of the qr shape
qr.Location = TextLocation.BelowEmbedded;
qr.Transform = new TranslateTransform(50, 400);
qr.Width = 50;
qr.Height = 50;
qr.Data = "your data here";

using (FileStream stream = new FileStream(
    @"..\..\out.pdf", FileMode.Create, FileAccess.Write))
{
    doc.Write(stream);
}
'create a new PDF and add a single page to it
Dim doc As New Document()
Dim page As New Page(PageSize.Letter)
doc.Pages.Add(page)

'create a new barcode shape and add it to the page
Dim shape As New Code3of9BarcodeShape()
page.VisualOverlay.Add(shape)

'specify some members of the barcode shape
shape.Location = TextLocation.BelowEmbedded
shape.Transform = New TranslateTransform(50, 600)
shape.Width = 200
shape.Height = 50
shape.Data = "123456789"

'create a new qr code shape and add it to the page
Dim qr As New QRBarcodeShape()
page.VisualOverlay.Add(qr)

'specify some members of the qr shape
qr.Location = TextLocation.BelowEmbedded
qr.Transform = New TranslateTransform(50, 400)
qr.Width = 50
qr.Height = 50
qr.Data = "your data here"

Using stream As New FileStream("..\..\out.pdf", FileMode.Create, FileAccess.Write)
	doc.Write(stream)
End Using