Back to Devexpress

PdfViewer.FindText(String, PdfTextSearchParameters) Method

windowsforms-devexpress-dot-xtrapdfviewer-dot-pdfviewer-dot-findtext-x28-system-dot-string-devexpress-dot-pdf-dot-pdftextsearchparameters-x29.md

latest5.8 KB
Original Source

PdfViewer.FindText(String, PdfTextSearchParameters) Method

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

Namespace : DevExpress.XtraPdfViewer

Assembly : DevExpress.XtraPdfViewer.v25.2.dll

NuGet Package : DevExpress.Win.PdfViewer

Declaration

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

Parameters

NameTypeDescription
textString

Specifies the text to find in the PDF document.

| | parameters | PdfTextSearchParameters |

Specifies the search parameters.

|

Returns

TypeDescription
PdfTextSearchResults

Contains information related to search results.

|

Remarks

Use the FindText method overloads to perform a search in a PDF document. The search starts from the current page defined by the CurrentPageNumber property. When you scroll the document and continue to search the same text again, the search continues from the currently visible page. Use the ContinueSearchFrom property to control how to continue a search in the document: from the current page (the default option) or the last search result.

The FindText method stops the search when it finds the first occurrence of the search term, highlights the occurrence and navigates to the highlighted text. See Search for a Specific Text for details.

When you change the search parameters (the search text, PdfTextSearchParameters.WholeWords, or PdfTextSearchParameters.CaseSensitive), the PDF Viewer starts a new search.

Note

The FindText method uses the page coordinate system. See the Coordinate Systems topic for more information.

Example

This example shows how to execute the Find Next action by pressing the F3 shortcut, after an end-user has specified text search options in the Find Text dialog.

To do this, handle the PdfViewer.KeyDown event. If the F3 key is pressed, call the overloaded PdfViewer.FindText method and pass the text to search and search parameters obtained from the Find Text dialog to this method.

The text search settings (e.g, search text, whole words, case sensitive) applied by an end-user in the Find Text dialog can be accessed using the PdfViewer.FindDialogOptions property.

csharp
using DevExpress.Pdf;
using DevExpress.XtraPdfViewer;
using System;
using System.Windows.Forms;

namespace FindTextUsingShortcut {
    public partial class Form1 : Form {
        public Form1() {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e) {
            pdfViewer1.LoadDocument(@"..\..\Report.pdf");
        }

        private void pdfViewer1_KeyDown(object sender, KeyEventArgs e) {
            if (e.KeyData == Keys.F3) {
                PdfTextSearchParameters parameters = new PdfTextSearchParameters();
                PdfFindDialogOptions options = pdfViewer1.FindDialogOptions;
                parameters.CaseSensitive = options.CaseSensitive;
                parameters.WholeWords = options.WholeWords;
                pdfViewer1.FindText(options.Text, parameters);
            }
        }
    }
}
vb
Imports DevExpress.Pdf
Imports DevExpress.XtraPdfViewer
Imports System
Imports System.Windows.Forms

Namespace FindTextUsingShortcut
    Partial Public Class Form1
        Inherits Form

        Public Sub New()
            InitializeComponent()
        End Sub

        Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            pdfViewer1.LoadDocument("..\..\Report.pdf")
        End Sub

        Private Sub pdfViewer1_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles pdfViewer1.KeyDown
            If e.KeyData = Keys.F3 Then
                Dim parameters As New PdfTextSearchParameters()
                Dim options As PdfFindDialogOptions = pdfViewer1.FindDialogOptions
                parameters.CaseSensitive = options.CaseSensitive
                parameters.WholeWords = options.WholeWords
                pdfViewer1.FindText(options.Text, parameters)
            End If
        End Sub
    End Class
End Namespace

See Also

PdfFindTextCommand

PdfViewer Class

PdfViewer Members

DevExpress.XtraPdfViewer Namespace