search method
- String query, {
- Set<
PdfSearchFlag> flags = const {}, - int? pageIndex,
Searches the document for query and streams all matches.
Results are yielded page-by-page in ascending page order. An empty stream
means no matches were found. An empty query string returns an empty
stream immediately without invoking any PDFium calls.
flags controls case-sensitivity, whole-word matching, and overlapping
matches. Defaults to case-insensitive, non-whole-word, non-overlapping.
When pageIndex is specified, the search is restricted to that single
page. Omit it to search all pages. Throws RangeError if pageIndex is
out of range for the document.
Bounding rectangles in each PdfSearchMatch are in PDF user-space
(origin bottom-left, units in points). Callers that need screen-space
coordinates must apply FPDF_PageToDevice() themselves.
Cancelling the stream subscription immediately stops further processing. Page-level PDFium handles are released inside the isolate after each round-trip, so there are no handle leaks on cancellation.
close terminates any active stream: the stream stops emitting events and the subscription is silently cancelled.
Throws StateError if the document has been closed before or during the search.
Platform support: Native (dart:ffi) only. Stubs on unsupported platforms throw UnsupportedError immediately.
Example — search for a term and print each match location:
await for (final match in doc.search('example')) {
print('Match on page ${match.pageIndex + 1}: '
'char ${match.charIndex}, '
'${match.rects.length} rect(s)');
}
Implementation
Stream<PdfSearchMatch> search(
String query, {
Set<PdfSearchFlag> flags = const {},
int? pageIndex,
}) => _impl.search(query, flags: flags, pageIndex: pageIndex);