XDoc.PDF
Features
Tech Specs
How-to C#
How-to VB.NET
Pricing
C# PDF: How to PDF Create PDF Export File and Page Process PDF Read PDF Write Form Process Document Protect Annotation & Drawing PDF Print WPF Viewer & Editor Work with Other SDKs Barcode Read Barcode Create OCR Twain
Text: Search Text in PDF
  |  
Home ›› XDoc.PDF ›› C# PDF: Search PDF Text

C#.NET PDF SDK - Search and Find PDF Text in C#.NET


C# Guide about How to Search Text in PDF Document and Obtain Text Content and Location Information with .NET PDF Control




Best Visual Studio .NET PDF document SDK , built on .NET framework 2.0 and compatible with Windows operating system


Free components and library are easy to be integrated in .NET WinForms application and ASP.NET for searching adobe PDF text in C# class


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


C# class sample code for searching text from specified PDF pages in .NET console application


Able to find and get PDF text position details in C#.NET application


Allow to search defined PDF file page or the whole document


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


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


XDoc.PDF for .NET allows C#.NET programmers to integrate text search functionality into their PDF document management application.






C# search text from pdf document


Note: When you get the error "Could not load file or assembly 'RasterEdge.Imaging.Basic' or any other assembly or one of its dependencies. An attempt to load a program with an incorrect format", please check your configure as follows:

       

       If you are using x64 libraries/dlls, Right click the project -> Properties -> Build -> Platform target: x64.

       

       If using x86, the platform target should be x86.




        #region search text from pdf document
        internal static void searchTextFromDocument()
        {
            String inputFilePath = @"C:\demo.pdf";
            // Open a document.
            PDFDocument doc = new PDFDocument(inputFilePath);
            // Set the search options
            RESearchOption option = new RESearchOption();
            option.IgnoreCase = true;
            option.WholeWord = true;
            option.ContextExpansion = 10;

            // Search text and save it to SearchResult.
            SearchResult results = doc.Search("RasterEdge", option);
        }
        #endregion




C# search text from specified pdf page





        #region search text from specified pdf page
        internal static void searchTextFromPDFPage()
        {
            String inputFilePath = @"C:\demo.pdf";
            // Open a document.
            PDFDocument doc = new PDFDocument(inputFilePath);
            // Set the search options
            RESearchOption option = new RESearchOption();
            option.IgnoreCase = true;
            option.WholeWord = true;
            option.ContextExpansion = 10;

            int pageIndex = 1;
            // Search text in second page and save it to SearchResult.
            SearchResult results = doc.Search("RasterEdge", option, pageIndex);
        }
        #endregion




C# search text from consecutive pdf pages





        #region search text from Consecutive pdf pages
        internal static void searchTextFromPages()
        {
            String inputFilePath = @"C:\demo.pdf";
            // Open a document.
            PDFDocument doc = new PDFDocument(inputFilePath);
            // Set the search options
            RESearchOption option = new RESearchOption();
            option.IgnoreCase = true;
            option.WholeWord = true;
            option.ContextExpansion = 10;

            int pageOffset = 1;
            int pageCount = 2;
            // Search text from second page
            // The second and third pages will be searched. 
            // Save it to SearchResult.
            SearchResult results = doc.Search("RasterEdge", option, pageOffset, pageCount);

        }
        #endregion




C# search and replace text from pdf document





        #region search and replace text from pdf document
        internal static void searchAndReplaceTextFromDocument()
        {
            String inputFilePath = @"C:\demo.pdf";
            // Open a document.
            PDFDocument doc = new PDFDocument(inputFilePath);

            // Set the search options.
            RESearchOption option = new RESearchOption();
            option.IgnoreCase = true;
            option.WholeWord = true;
            option.ContextExpansion = 10;

            // Replace "RasterEdge" with "Image".
            doc.Replace("RasterEdge", "Image", option);
            doc.Save(@"C:\output.pdf");
        }
        #endregion




.NET Class Namespace Required



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.XImage.Raster.dll


  RasterEdge.XImage.Raster.Core.dll


  RasterEdge.XDoc.PDF.dll


Use corresponding namespaces;


  using RasterEdge.Imaging.Basic;


  using RasterEdge.XDoc.PDF;


  using RasterEdge.Imaging.Basic.TextSearch;





public SearchResult Search(String matchString, RESearchOption option)

Description:
     Search specified string from all the PDF pages.

Parameters:

Return:
     The results of search, it will include a list of SearchResultItem.



public SearchResult Search(String matchString, RESearchOption option, int pageIndex)

Description:
     Search specified string from specified page.

Parameters:

Return:
     The results of search, it will include a list of SearchResultItem.



public SearchResult Search(String matchString, RESearchOption option, int pageOffset, int pageCount)

Description:
     Search specified string from the specified pages from pageOffse to pageOffset + pageCount - 1.

Parameters:

Return:
     The results of search, it will include a list of SearchResultItem.