officefileapi-devexpress-dot-pdf-dot-pdfdocumentprocessor-dot-findtext-x28-system-dot-string-devexpress-dot-pdf-dot-pdftextsearchparameters-x29.md
Searches for the specified text in the current document with the applied parameters.
Namespace : DevExpress.Pdf
Assembly : DevExpress.Docs.v25.2.dll
NuGet Package : DevExpress.Document.Processor
public PdfTextSearchResults FindText(
string text,
PdfTextSearchParameters parameters
)
Public Function FindText(
text As String,
parameters As PdfTextSearchParameters
) As PdfTextSearchResults
| Name | Type | Description |
|---|---|---|
| text | String |
A String value, specifying the text to find in the PDF.
| | parameters | PdfTextSearchParameters |
A PdfTextSearchParameters object.
|
| Type | Description |
|---|---|
| PdfTextSearchResults |
A PdfTextSearchResults object.
|
The overloaded FindText method uses the page coordinate system. Refer to the Coordinate Systems topic for more information.
This example shows how to create a bookmark with a destination that displays the page as follows:
using System.Collections.Generic;
using DevExpress.Pdf;
using (PdfDocumentProcessor documentProcessor = new PdfDocumentProcessor())
{
// Load a document
documentProcessor.LoadDocument(@"..\..\Document.pdf");
// Define search words
string[] words = { "DX-B5000", "DX-RX800" };
// Specify search parameters
PdfTextSearchParameters searchParameters = new PdfTextSearchParameters();
searchParameters.CaseSensitive = true;
searchParameters.WholeWords = true;
foreach (string word in words)
{
// Get search results
PdfTextSearchResults results = documentProcessor.FindText(word, searchParameters);
// If the text is found, create a destination that positions the found text
// at the upper window corner
if (results.Status == PdfTextSearchStatus.Found)
{
PdfXYZDestination destination = new PdfXYZDestination(results.Page, 0, results.Rectangles[0].Top, null);
// Create a bookmark associated with the destination
PdfBookmark bookmark = new PdfBookmark() { Title = word, Destination = destination };
// Add the bookmark to the bookmark list
documentProcessor.Document.Bookmarks.Add(bookmark);
}
}
// Save the modified document
documentProcessor.SaveDocument(@"..\..\Result.pdf");
}
Imports System.Collections.Generic
Imports DevExpress.Pdf
Using documentProcessor As New PdfDocumentProcessor()
' Load a PDF document
documentProcessor.LoadDocument("..\..\Document.pdf")
' Define search words
Dim words() As String = { "DX-B5000", "DX-RX800" }
' Specify search parameters
Dim searchParameters As New PdfTextSearchParameters()
searchParameters.CaseSensitive = True
searchParameters.WholeWords = True
For Each word As String In words
' Get search results
Dim results As PdfTextSearchResults = documentProcessor.FindText(word, searchParameters)
' If the text is found, create a destination that positions the found text
' at the upper window corner
If results.Status = PdfTextSearchStatus.Found Then
Dim destination As New PdfXYZDestination(results.Page, 0, results.Rectangles(0).Top, Nothing)
' Create a bookmark associated with the bookmark
Dim bookmark As New PdfBookmark() With {.Title = word, .Destination = destination}
' Add the bookmark to the bookmark list
documentProcessor.Document.Bookmarks.Add(bookmark)
End If
Next word
' Save the modified document
documentProcessor.SaveDocument("..\..\Result.pdf")
End Using
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.
pdf-document-api-bookmark-search-results-in-document/CS/Destination/Program.cs#L27
// Get the search results from the FindText method called with search text and search parameters.
PdfTextSearchResults results = documentProcessor.FindText(word, searchParameters);
pdf-document-api-bookmark-search-results-in-document/VB/Destination/Program.vb#L23
' Get the search results from the FindText method called with search text and search parameters.
Dim results As DevExpress.Pdf.PdfTextSearchResults = documentProcessor.FindText(word, searchParameters)
' If the desired text is found, create a destination that corresponds to the found text
See Also