Next callfunction CreateDocumentSearch(const Text: WString; Options: TSearchOptions = []; StartPage: Integer = 0; Direction: TPdfDocumentSearchDirection = dsdForward; const CancellationToken: IPdfCancellationToken = nil): TPdfDocumentSearch;
| Text | Non-empty Unicode text without embedded null characters |
| Options | Native PDFium case-sensitive, whole-word, and consecutive-match options |
| StartPage | One-based first page, or 0 for page 1 when searching forwards and the final page when searching backwards |
| Direction | dsdForward or dsdBackward |
| CancellationToken | Optional cooperative cancellation token checked at page boundaries and before each match is published |
TPdfDocumentSearch instanceThe search opens only its current page, text page, and native search handle, releasing them before it advances to the next page, so native handle memory does not grow with document length
Next returns the page number, native character range, matched text, and all page-space rectangles in one result record, avoiding a page switch or a second page parse for highlighting
An empty active document produces an already finished search. Closing the owner document, or changing its page tree with AddPage, DeletePage, ImportPages, ImportPagesByIndex or MovePages, safely finishes every outstanding search; create a new search afterwards. Do not edit page content whilst a search is being advanced
var
Search: TPdfDocumentSearch;
Match: TPdfDocumentSearchResult;
begin
Search := Pdf1.CreateDocumentSearch('invoice');
try
while Search.Next(Match) do
Memo1.Lines.Add(Format('Page %d, character %d', [Match.PageNumber, Match.StartIndex]));
finally
Search.Free;
end;
end;