Download and Process file | VB.NETByteScout Text Recognition SDK

Download and Process file | VB.NET

Module1.vb:

VB
Imports System
Imports System.Diagnostics
Imports System.IO
Imports Bytescout.TextRecognition

Module Module1

    Sub Main()

        ' Input file url
        Dim inputFileUrl As String = "https://bytescout-com.s3.amazonaws.com/files/demo-files/cloud-api/image-to-pdf/image1.png"
        Dim outputDocument As String = ".\result.txt"

        ' Input stream 
        Dim inputStream As Stream = GetStreamFromUrl(inputFileUrl)

        ' Create and activate TextRecognizer instance
        Using textRecognizer As TextRecognizer = New TextRecognizer("demo", "demo")

            Try
                ' Load document (image or PDF)
                textRecognizer.LoadDocument(inputStream)

                ' Set the location of OCR language data files
                textRecognizer.OCRLanguageDataFolder = "C:\Program Files\ByteScout Text Recognition SDK\ocrdata_best\"

                ' Set OCR language.
                ' "eng" for english, "deu" for German, "fra" for French, "spa" for Spanish, etc. - according to files in "ocrdata" folder
                ' Find more language files at https://github.com/bytescout/ocrdata
                textRecognizer.OCRLanguage = "eng"

                ' Recognize text from all pages and save it to file
                textRecognizer.SaveText(outputDocument)

                ' Open the result file in default associated application (for demo purposes)
                Process.Start(outputDocument)

            Catch exception As Exception

                Console.WriteLine(exception)

            End Try

        End Using

    End Sub

    ''' <summary>
    ''' Get stream from Url
    ''' </summary>
    Private Function GetStreamFromUrl(ByVal url As String) As Stream

        Dim oData As Byte() = Nothing

        Using wc As New System.Net.WebClient()
            oData = wc.DownloadData(url)
        End Using

        Return New MemoryStream(oData)

    End Function

End Module