PDF Barcode VB.NET Library
How to scan, read barcode from PDF file using VB.NET code?
VB.NET Guide for Decoding Linear and 2D Barcodes from PDF in VB.NET Class
In this Visual Basic .NET tutorial, you will know how to scan, read linear and 2d barcodes from PDF file in VB.NET applications
- Read Code 39, Code 128, EAN/UPC, GS1 128 linear barcodes from PDF
- Read Data Matrix, PDF-417 and QR Code 2d barcodes from PDF
- Scan multiple barcode types at one time from a PDF file
- Scan multiple directions inside a PDF page
- Read barcode from partial page area or whole page
- Easy to integrate in Windows Forms, WPF applications, ASP.NET using VB.NET
How to read, scan barcode from PDF file using Visual Basic .NET
One of the solutions by which you can use to improve your PDF document reading with high capacity is to embed a barcode reader add-on. And here, we specifically recommend this VB.NET PDF barcode reading application to you. This PDF barcode decoding library SDK for VB.NET class is exclusively designed for detecting and reading most common linear and two-dimensional barcode symbols from PDF document using VB.NET methods.
Scan, read barcode from PDF file using VB.NET
The following guide and VB.NET source code will show how to quickly scan and read a Code 128 barcode from PDF file in VB.NET code.
- Define a new PDFDocument object with an existing PDF file loaded
- Create a new ReaderSettings object with barcode scan options applied
- Call BarcodeReader.ReadBarcodes() to read, scan all Code 128 barcodes from the PDF document.
Dim inputFilePath As String = "C:\1.pdf"
' Open PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' Initial reader's setting
Dim settings As ReaderSettings = New ReaderSettings()
' Set target barcode type to Code128
settings.AddTypesToRead(BarcodeType.Code128)
' Scan barcodes from the document.
Dim result As Barcode() = BarcodeReader.ReadBarcodes(settings, doc)
If result.Length > 0 Then
For Each barcode In result
Console.WriteLine("Barcode Data: " + barcode.DataString)
Next
Else
Console.WriteLine("[No Barcode Found]")
End If
Barcode Read Options
In your VB.NET code, you can use class "ReaderSettings" to apply the barcode read options. The class is used to configure the barcode reader.
- Direction: Type: ScanDirection. Gets and sets the direction of reading the source image.
Enum: ScanDirection
- Undefined: Scan the source in different directions and stop once the 1st barcode is found.
- LeftToRight: Scan the source from left to right only.
- TopToBottom: Scan the source from top to bottom only
- RightToLeft: Scan the source from right to left only.
- BottomToTop: Scan the source from bottom to top only.
- Horizontal: Scan the source in horizontal.
Equivalent to: LeftToRight | RightToLeft
- Vertical: Scan the source in vertical.
Equivalent to: TopToBottom | BottomToTop
- All: Scan the source in all 4 directions.
- RegionOfInterest: Specifies the region on the source image of which it would scan.
Unit: in percent
Remarks:
X, Y, (X + Width) and (Y + Height) of the Rectangle must be in the range of 0 to 100; otherwise, the region is the whole image.
- NumberOfBarcodeToRead: Limit the number of barcode that read from the source.
MoreThanOne: read all barcodes.
Barcode Result Information
Once you have scanned the PDF file, and you will get a list of Barcode object. Each object contain returned barcode information.
- Type: Gets type of the found barcode.
- RawData: Gets barcode message data in byte array
- DataString: Gets barcode message data in string.
- BeginLine: Gets the begin line segment of the barcode, which usually is the left edge of the barcode boundary.
- EndLine: Gets the end line segment of the barcode, which usually is the right edge of the barcode boundary.
- BoundingRectangle: Gets the minimum bounding rectangle of the barcode.
- Direction: Gets the direction of the barcode.
LeftToRight: from left to right
TopToBottom: from top to bottom
RightToLeft: from right to left
BottomToTop: from bottom to top
Scan and read multiple barcode types from PDF file using VB.NET
The following contents and VB.NET example source code will show how to scan, read more than one barcode types from a PDF file in VB.NET code.
- Define a new PDFDocument with an existing PDF file loaded
- Define a new ReaderSettings object
- Add three barcode types for scanning: Code 128, Data Matrix, and QR Code to ReaderSettings object
- Call BarcodeReader.ReadBarcodes() to read, scan all these three barcodes from PDF document.
Dim inputFilePath As String = "C:\1.pdf"
' Open PDF file
Dim doc As PDFDocument = New PDFDocument(inputFilePath)
' Initial reader's setting
Dim settings As ReaderSettings = New ReaderSettings()
' Set multiple target barcode types to Code128, DataMatrix And QRCode
settings.AddTypesToRead(BarcodeType.Code128)
Settings.AddTypesToRead(BarcodeType.DataMatrix)
Settings.AddTypesToRead(BarcodeType.QRCode)
' Scan barcodes from the document.
Dim result As Barcode() = BarcodeReader.ReadBarcodes(settings, doc)
If (result.Length > 0) Then
For Each barcode In result
Console.WriteLine("Barcode Type: " + barcode.Type.ToString())
Console.WriteLine("Barcode Data: " + Barcode.DataString)
Next
Else
Console.WriteLine("[No Barcode Found]")
End If