search text in PDF

This article shows how to search a PDF for text in C# using the Document.Find method and the TextFindCriteria and TextMatchEnumerator classes.

This code sample visualizes the results by saving a copy of the searched document with all matches highlighted and marked with the match position (first match, second match, etc.).

Resulting PDF page

This is what the result of the below code sample looks like:

C# code sample - search text in PDF

It is possible to search text on a specific page by calling Page.Find or in the entire PDF document by calling Document.Find. The signature of both methods is the same. The search criteria are defined by passing a TextFindCriteria instance. The results are returned as a TextMatchEnumerator instance. This code sample demonstrates Document.Find but everything applies to Page.Find as well.