C# code tutorial

PDF Extracting PDF Creating & Inserting PDF to Image PDF Digital Signature PDF Processing & Editing PDF Protecting PDF Chart PDF Barcode

Popular .NET SDK


Text search in PDF document is the most commonly used functionality of PDF document manipulation. XsPDF provides mature .NET APIs for searching text from PDF document for your C# WinForms, WPF and ASP.NET web projects. It is quite easy to integrate XsPDF .NET pdf library to your project and implement highly accurate PDF text searching.

You are allowed to search text from the whole PDF document or just a specific page. And there are two mature method for you to choose while implement text search in PDF, which are MatchCase and MatchWholeWord. By setting MatchCase to false, text search will be implemented by ignoring the uppercase and lowercase of search text. Both of them will be found as results, for instance, searching "PDF", you may get pdf and Pdf. As for MatchWholeWord, you may obtain PDF, PDFs and XsPDF as results by setting it to false.

XsPDF text extractor is designed to extract text from Adobe PDF files for use in other applications. To extract text from a PDF file, the PDF file must meet the condition which is formatted to contain text and not just images, otherwise, you may need the PDF OCR tool, it can recognize text from PDF and images.

By using XsPDF APIs, the match text will be searched and found easily and accurately, no matter where it is, in page header, footer, paragraphs, form, or table. You may directly use the following C# sample code to have a quick evaluation of this functionality. It is also easy to implement PDF text search in ASP.NET web application. You can search text from whole PDF file and a specified page. Moreover, text found will be marked.


// Read a local PDF file in the disk
PdfTextExtractor extractor = new PdfTextExtractor("sample.pdf");

extractor.MatchCase = true; 
extractor.MatchWholeWord = true;

List<TextInfo> infos = extractor.SearchText("search text");
foreach (TextInfo info in infos)
{
    Console.WriteLine(info.Text);
    Console.WriteLine(info.Rect.X + "-" + info.Rect.Y);
    Console.WriteLine(info.PageId);
}

More Excel tutorial