PdfViewer.FindText(String, PdfTextSearchParameters) Method
Searches for the specified text in the current document with the given parameters.
Namespace: DevExpress.XtraPdfViewer
Assembly: DevExpress.XtraPdfViewer.v18.2.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
text | String | Specifies the text to find in the PDF document. |
parameters | PdfTextSearchParameters | Specifies the search parameters. |
Returns
Type | Description |
---|---|
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 last found result. Use the ContinueSearchFrom property to control how to continue a search in the document: from the currently active page or the last search result (the default option).
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-find-text-using-a-keyboard-shortcut-t601532
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);
}
}
}
}
Related GitHub Examples
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the FindText(String, PdfTextSearchParameters) 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.