VB.NET PDF: How to HTML5 PDF Viewer PDF Create PDF Export File & Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF PDF Viewer Work with Other SDKs Barcode Read Barcode Create OCR Twain
Text: Search Text in PDF
  |  
Home ›› XDoc.PDF ›› VB.NET PDF: Search PDF Text

VB.NET PDF - Search and Find PDF Text in VB.NET


Learn How to Search Text in PDF Document and Obtain Text Content and Location Information in VB.NET application




Best Visual Studio .NET PDF document SDK, built in .NET framework 2.0 and compatible with VB.NET programming language


Easy to search and find text content in multiple page adobe PDF files in .NET WinForms and ASP.NET


Search text in PDF images by using XDoc.PDF SDK for VB.NET


Support .NET WinForms, ASP.NET MVC in IIS, ASP.NET Ajax, Azure cloud service, DNN (DotNetNuke), SharePoint


Help to find and get PDF text position details in Visual Basic class program


Allow to search defined PDF file page or the whole document


Support various search options, like whole word, ignore case, match string, etc


Ability to search and replace PDF text programmatically in VB.NET


VB.NET class online source code and free VB.NET XDoc.PDF library and component are available


If the source PDF document is with multiple pages, it may be difficult for you to find certain text from the Microsoft PDF document page. Our VB.NET PDF Document Add-On enables you to search for text in target PDF document by using PDFPage class. Once you have found the text, various operations are available according to specific needs. For example, you can locate the searched text together with methods stated above.


API and VB.NET sample code below can be utilized to search for text in target PDF document in your Visual Studio project using VB language. Furthermore, if you are a Visual C# .NET programmer, you can go to this Visual C# tutorial for PDF text search in .NET project.




VB.NET Code Example of Finding Text



Add necessary references:


  RasterEdge.Imaging.Basic.dll


  RasterEdge.Imaging.Basic.Codec.dll


  RasterEdge.Imaging.Drawing.dll


  RasterEdge.Imaging.Font.dll


  RasterEdge.Imaging.Processing.dll


  RasterEdge.XDoc.Raster.dll


  RasterEdge.XDoc.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;


  using RasterEdge.Imaging.Basic.TextSearch;


The following coding example illustrates how to perform PDF text searching function in your VB.NET project, including setting search option, creating search result, and saving the result.




Public Shared Function TestSearch(ByVal fileName As String, ByVal matchString As String, ByVal cacheFile As String)

    ' Set search options.
    Dim options As RESearchOption = New RESearchOption()
    options.SetMatchString(matchString)
    options.WholeWord = True
    options.IgnoreCase = True
    options.ContextExpansion = 30

    ' It will create a cach file if your PDF document is never been searched before. 
    If Not File.Exists(fileName) Then
        Dim document As BaseDocument = getBaseDocument(TestFilePath.InputFilePath + fileName)
        document.CacheSearchInfo(TestFilePath.InputFilePath + cacheFile)
    End If

    ' Create search result.
    Dim sResult As SearchResult = New SearchResult()

    ' Search and store the result in the entity of search structure.
    BaseDocument.Search(TestFilePath.InputFilePath + cacheFile, options, sResult)

End Function

Private Shared Function getBaseDocument(ByVal filePath As String) As BaseDocument

    Dim document As BaseDocument
    If filePath.EndsWith(".pdf") Then
        document = New PDFDocument(filePath)
    ElseIf (filePath.EndsWith(".docx")) Then
        document = New DOCXDocument(filePath)
    ElseIf (filePath.EndsWith(".xlsx")) Then
        document = New XLSXDocument(filePath)
    Else
        document = Nothing
    End If

    Return document

End Function