New to Telerik Document ProcessingStart a free 30-day trial

Search

Updated on May 11, 2026

This feature allows you to search for a specific text in a PDF document. You can use plain text or a regex for the search criteria. There are various methods that allow you to find all occurrences at once or one by one.

The TextSearch class

This class exposes methods for searching. You need to pass an instance of RadFixedDocument when creating a new instance. This is the document that will be searched.

Example 1: Create TextSearch Instance

C#
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(File.ReadAllBytes(@"Test.pdf"), TimeSpan.FromSeconds(10));

TextSearch search = new TextSearch(document);
IEnumerable<SearchResult> result = search.FindAll("Lorem", TextSearchOptions.Default);

Search Methods

The TextSeach class exposes the following methods which allow you to search the document:

MethodDescription
Find(string text, TextSearchOptions options)Finds the first occurrence of the specified string starting from the beginning of the document. Optionally accepts a start position or a specific range.
FindPrevious(string text, TextSearchOptions options)Finds the previous occurrence of the specified text. Optionally accepts a start position or a specific range.
FindAll(string text, TextSearchOptions options)Finds all occurrences of the specified text. Optionally accepts a start position or a specific range.

SearchResult class

All of the above methods return one or more instances of the SearchResult class. This class exposes the following public members that provide information about the results:

MemberDescription
TextRangeAn object describing the start and end positions of the match. Exposes StartPosition (start index and location) and EndPosition (end index and location).
ResultA string value representing the match.
GetWordBoundingRect()Gets the rectangle of the current match.
GetResultPage()Gets the page where the current result is.

Example 2: Searching in a document

C#
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(File.ReadAllBytes(@"Test.pdf"), TimeSpan.FromSeconds(10));

TextSearch search = new TextSearch(document);
IEnumerable<SearchResult> result = search.FindAll("Lorem", TextSearchOptions.Default);

foreach (SearchResult resultItem in result)
{
    Rect rect = resultItem.GetWordBoundingRect();
    RadFixedPage page = resultItem.GetResultPage();
    FixedContentEditor editor = new FixedContentEditor(page);
    editor.DrawRectangle(rect);
}

File.WriteAllBytes(@"result.pdf", provider.Export(document, TimeSpan.FromSeconds(10)));

TextSearchOptions

The TextSearchOptions class exposes the following properties which allow you to set the search parameters:

PropertyDescription
UseRegularExpressionGets or sets a value indicating whether a regular expression should be used for searching.
CaseSensitiveGets or sets a value indicating whether the search should be case sensitive.
WholeWordsOnlyGets or sets a value indicating whether only whole words should be matched.