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

How to: Search Text in a Document

  • 2 minutes to read

Important

The Universal Subscription or an additional Document Server Subscription is required to use this example in production code. Please 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.

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()) {
                    documentProcessor.LoadDocument(filePath);
                    while (documentProcessor.FindText(word).Status == PdfTextSearchStatus.Found) {
                        count++;
                    }
                }
            }
            catch { }

            return count;
        }