Back to Devexpress

PdfDocumentProcessor.FindText(String) Method

officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-dot-findtext-x28-system-dot-string-x29.md

latest4.7 KB
Original Source

PdfDocumentProcessor.FindText(String) Method

Searches for the specified text in the current document with default parameters.

Namespace : DevExpress.Pdf

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public PdfTextSearchResults FindText(
    string text
)
vb
Public Function FindText(
    text As String
) As PdfTextSearchResults

Parameters

NameTypeDescription
textString

A String value, specifying the text to find in the PDF.

|

Returns

TypeDescription
PdfTextSearchResults

A PdfTextSearchResults object.

|

Remarks

The overloaded FindText method uses the page coordinate system. Refer to the Coordinate Systems topic for more information.

The following code snippet counts all words in a document.

View Example

csharp
using DevExpress.Pdf;
// ...

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;
}
vb
Imports DevExpress.Pdf
' ...
Private Function WordCount(ByVal filePath As String, ByVal word As String) As Integer
    Dim count As Integer = 0
    Try
        Using documentProcessor As New PdfDocumentProcessor()
            documentProcessor.LoadDocument(filePath)
            Do While documentProcessor.FindText(word).Status = PdfTextSearchStatus.Found
                count += 1
            Loop
        End Using
    Catch
    End Try

    Return count
End Function

The following code snippets (auto-collected from DevExpress Examples) contain references to the FindText(String) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

pdf-document-api-add-link-to-page/CS/AddLinkToPage/Program.cs#L21

csharp
string linkText = "JBIG2 images";
PdfTextSearchResults linkSearchResults = pdfDocumentProcessor.FindText(linkText);

pdf-document-api-add-link-to-uri/CS/AddLinkToUri/Program.cs#L20

csharp
string linkText = "PDF Viewer";
PdfTextSearchResults linkSearchResults = processor.FindText(linkText);

pdf-document-api-add-link-to-page/VB/AddLinkToPage/Program.vb#L21

vb
Dim linkText As String = "JBIG2 images"
Dim linkSearchResults As PdfTextSearchResults = processor.FindText(linkText)

pdf-document-api-add-link-to-uri/VB/AddLinkToUri/Program.vb#L19

vb
Dim linkText As String = "PDF Viewer"
Dim linkSearchResults As PdfTextSearchResults = processor.FindText(linkText)

See Also

PdfDocumentProcessor Class

PdfDocumentProcessor Members

DevExpress.Pdf Namespace