Skip to main content
A newer version of this page is available. .

How to: Search Text in a Document

  • 2 minutes to read


You require a license to the DevExpress Office File API or DevExpress Universal Subscription to use these examples in production code. Refer to the DevExpress Subscription page for pricing information.

This example demonstrates how to count the occurrences of words in a document text.

To accomplish this task, do the following.

The code sample below counts all words in a document.

using DevExpress.Pdf;
using DevExpress.XtraBars;
using DevExpress.XtraEditors;
using System.IO;
using System.Text;
using System.Windows.Forms;
// ...
        private int WordCount(string filePath, string word) {
            int count = 0;
            try {
                using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor()) {
                    while (documentProcessor.FindText(word).Status == PdfTextSearchStatus.Found) {
            catch { }

            return count;