Link Search Menu Expand Document

Find Email Addresses in PDF using Regex - VB.NET

PDF Extractor SDK sample in VB.NET demonstrating ‘Find Email Addresses in PDF using Regex’

Imports Bytescout.PDFExtractor

' Note: if you are looking for a more higher level API to extract data from invoices, reports, statements
' then please check Document Parser SDK and Web API at
' and for secure and scalable web api

Module Program

    Sub Main()

            ' Create Bytescout.PDFExtractor.TextExtractor instance
            Using extractor As TextExtractor = New TextExtractor()
                extractor.RegistrationName = "demo"
                extractor.RegistrationKey = "demo"

                ' Load sample PDF document

                ' Enable the regular expression 
                extractor.RegexSearch = True

                Dim pageCount As Integer = extractor.GetPageCount()

                ' Search through pages
                For i As Integer = 0 To pageCount - 1
                    ' Search Email addresses
                    Dim regexPattern As String = "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b"
                    ' See the complete regular expressions reference at

                    ' Search each page for the pattern
                    If extractor.Find(i, regexPattern, False) Then

                            ' Iterate through each element in the found text
                            For Each element As ISearchResultElement In extractor.FoundText.Elements
                                Console.WriteLine("Found Email Addresses: " & element.Text)
                        Loop While extractor.FindNext()

                    End If
            End Using

        Catch ex As Exception
            Console.WriteLine("Error: " & ex.Message)
        End Try

        Console.WriteLine("Press enter key to continue...")

    End Sub

End Module

Download Source Code (.zip)

Return to the previous page Explore PDF Extractor SDK

Copyright © 2016 - 2023 ByteScout