Link Search Menu Expand Document

Advanced Conversion Options - VB.NET

Barcode Reader sample in VB.NET demonstrating ‘Advanced Conversion Options’

Imports System.IO
Imports System.Net
Imports Newtonsoft.Json
Imports Newtonsoft.Json.Linq

Module Module1

    ' The authentication key (API Key).
    ' Get your own by registering at
    Const API_KEY As String = "***********************************"

    ' Direct URL of source file to search barcodes in.
    ' You can also upload your own file into and use it as url. Check "Upload File" samples for code snippets:   
    Const SourceFileURL As String = ""
    ' Comma-separated list of barcode types to search. 
    ' See valid barcode types in the documentation
    Const Pages As String = ""

    ' Some of advanced options available through profiles:
    ' (JSON can be single/double-quoted and contain comments.)
    ' {
    '     "profiles": [
    '         {
    '             "profile1": {
    '                 "ScanArea": "WholePage", // Values: "TopLeftQuarter", "TopRightQuarter", "BottomRightQuarter", "BottomLeftQuarter", "TopHalf", "BottomHalf", "WholePage".
    '                 "RequireQuietZones": true, // Whether the quite zone is obligatory for 1D barcodes. Values: true / false
    '                 "MaxNumberOfBarcodesPerPage": 0, // 0 - unlimited.
    '                 "MaxNumberOfBarcodesPerDocument": 0, // 0 - unlimited.
    '                 "ScanStep": 1, // Scan interval for linear (1-dimensional) barcodes.
    '                 "MinimalDataLength": 0, // Minimal acceptable length of decoded data.                
    '             }
    '         }
    '     ]
    ' }

    ' Sample profile that sets advanced conversion options
    ' Advanced options are properties of Reader class from Bytescout BarCodeReader used in the back-end:
    ' https//
    ReadOnly Profiles = File.ReadAllText("profile.json")

    Sub Main()

        ' Create standard .NET web client instance
        Dim webClient As WebClient = New WebClient()

        ' Set API Key
        webClient.Headers.Add("x-api-key", API_KEY)

        ' Set JSON content type
        webClient.Headers.Add("Content-Type", "application/json")

        ' Prepare URL for `Barcode Reader` API call
		Dim url As String = ""

        ' Prepare requests params as JSON
        ' See documentation: https : //
        Dim parameters As New Dictionary(Of String, Object)
		parameters.Add("pages", Pages)
		parameters.Add("url", SourceFileURL)
		parameters.Add("profiles", Profiles)

        ' Convert dictionary of params to JSON
        Dim jsonPayload As String = JsonConvert.SerializeObject(parameters)

            ' Execute POST request with JSON payload
            Dim response As String = webClient.UploadString(url, jsonPayload)

            ' Parse JSON response
            Dim json As JObject = JObject.Parse(response)

            If json("error").ToObject(Of Boolean) = False Then

                ' Display found barcodes in console
                For Each token As JToken In json("barcodes")
                    Console.WriteLine("Found barcode:")
                    Console.WriteLine("  Type: " + token("TypeName").ToString())
                    Console.WriteLine("  Value: " + token("Value").ToString())
                    Console.WriteLine("  Document Page Index: " + token("Page").ToString())
                    Console.WriteLine("  Rectangle: " + token("Rect").ToString())
                    Console.WriteLine("  Confidence: " + token("Confidence").ToString())

            End If

        Catch ex As WebException
        End Try


        Console.WriteLine("Press any key...")

    End Sub

End Module

  "profiles": [
      "profile1": {
        "FastMode": true
} Web API: the Web API with a set of tools for documents manipulation, data conversion, data extraction, splitting and merging of documents. Includes image recognition, built-in OCR, barcode generation and barcode decoders to decode bar codes from scans, pictures and pdf.

Get your API key here!

Download Source Code (.zip)

return to the previous page explore Barcode Reader endpoint