ByteScout Barcode Reader SDK - VB.NET - Split PDF Document By Found Barcode - ByteScout

ByteScout Barcode Reader SDK – VB.NET – Split PDF Document By Found Barcode

  • Home
  • /
  • Articles
  • /
  • ByteScout Barcode Reader SDK – VB.NET – Split PDF Document By Found Barcode

How to split PDF document by found barcode in VB.NET with ByteScout BarCode Reader SDK

Write code in VB.NET to split PDF document by found barcode with this step-by-step tutorial

With this source code sample you may quickly learn how to split PDF document by found barcode in VB.NET. ByteScout BarCode Reader SDK can split PDF document by found barcode. It can be used from VB.NET. ByteScout BarCode Reader SDK is the barcode decoder with support for code 39, code 128, QR Code, Datamatrix, GS1, PDF417 and all other popular barcodes. Can read barcodes from images, pdf, tiff documents and live web camera. Supports noisy and damaged documents, can split and merge pdf and tiff documents based on barcodes. Can export barcode decoder results to XML, JSON, CSV and into custom data structures.

The SDK samples like this one below explain how to quickly make your application do split PDF document by found barcode in VB.NET with the help of ByteScout BarCode Reader SDK. Follow the instructions from the scratch to work and copy the VB.NET code. Detailed tutorials and documentation are available along with installed ByteScout BarCode Reader SDK if you’d like to dive deeper into the topic and the details of the API.

Download free trial version of ByteScout BarCode Reader SDK from our website with this and other source code samples for VB.NET.

Try ByteScout BarCode Reader SDK today: Get 60 Day Free Trial or sign up for Web API

Module1.vb
      
Imports System.IO Imports System.Text Imports Bytescout.BarCodeReader Module Module1 Sub Main() Const inputFile As String = "Barcodes.pdf" Console.WriteLine("Reading barcode(s) from image {0}", Path.GetFullPath(inputFile)) ' Create Bytescout.BarCodeReader.Reader instance Dim reader As New Reader() reader.RegistrationName = "demo" reader.RegistrationKey = "demo" ' Set barcode type to find reader.BarcodeTypesToFind.Code39 = True ' ----------------------------------------------------------------------- ' NOTE: We can read barcodes from specific page to increase performance . ' For sample please refer to "Decoding barcodes from PDF by pages" program. ' ----------------------------------------------------------------------- ' Find barcode in PDF document reader.ReadFrom(inputFile) ' Method 1: Split PDF document in two parts by found barcode ' NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only reader.SplitDocument("barcodes.pdf", "part1.pdf", "part2.pdf", reader.FoundBarcodes(0).Page + 1) ' Method 2: Extract page containing the barcode from PDF document ' NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only reader.ExtractPageFromDocument("barcodes.pdf", "extracted_page.pdf", reader.FoundBarcodes(0).Page + 1) ' Method 3: Split PDF document into parts in one pass. ' NOTE: In Full version of the SDK this method is unlocked in "PRO" license type only. Dim pageRanges As StringBuilder = New StringBuilder() ' Create string containing page ranges to extract in the form "1-4,6-8,10-11,12-". Page numbers are 1-based! For i As Integer = 0 To reader.FoundBarcodes.Length - 1 Dim barcode As FoundBarcode = reader.FoundBarcodes(i) ' Add pages before the first barcode found If i = 0 And barcode.Page > 0 Then pageRanges.Append("1") If barcode.Page > 1 Then pageRanges.Append("-") pageRanges.Append(barcode.Page) End If pageRanges.Append(",") End If ' Add page with barcode pageRanges.Append(barcode.Page + 1) ' +1 because we skip the page with barcode and another +1 because need 1-based page numbers ' Add range untill the next barcode If i < reader.FoundBarcodes.Length - 1 Then If reader.FoundBarcodes(i + 1).Page - barcode.Page > 1 Then pageRanges.Append("-") pageRanges.Append(reader.FoundBarcodes(i + 1).Page) End If pageRanges.Append(",") Else ' for the last found barcode add ending "-" meaning "to the last page" pageRanges.Append("-") End If Next ' Split document Dim splittedParts As String() = reader.SplitDocument("barcodes.pdf", pageRanges.ToString()) ' The method returns array of file names. Rename files as desired. ' Cleanup reader.Dispose() For Each fileName As String In splittedParts Console.WriteLine(fileName) Next Console.WriteLine("Press enter key to exit...") Console.ReadLine() End Sub End Module

Try ByteScout BarCode Reader SDK today: 60 Day Free Trial (on-premise version) or sign up for Web API (on demand version)

VIDEO

ON-PREMISE VERSION

Get 60 Day Free Trial or Visit ByteScout BarCode Reader SDK page

Explore ByteScout BarCode Reader SDK documentation

WEB API

Sign Up for free Web API key

Explore Web API Documentation

Tutorials:

prev
next