Search
Find text in a PDF with NexPDF for Flutter and get the page and rectangle of every match.
License module
Search is part of the viewer module and works without a key.
search(query) searches every page, case-insensitively, in reading order, and returns a list of
NexPdfSearchHit. An empty query returns no hits.
for (final hit in doc.search('termination')) {
print('page ${hit.page + 1}: ${hit.context}');
}| Field | Meaning |
|---|---|
page | 0-based page index |
context | The text around the match |
llx, lly, urx, ury | The rectangle of the match in PDF points |
Draw the hits on a page
Map a hit onto a rendered page with pageView:
const scale = 144 / 72; // the page was rendered at 144 dpi
final view = doc.pageView(hit.page);
final (left, top, right, bottom) = view.rectToView(hit.llx, hit.lly, hit.urx, hit.ury, scale);
final box = Rect.fromLTRB(left, top, right, bottom); // draw it over the ImageNexPdfViewerWidget already does this: its search highlights every hit. See
Reader.
Highlight every match
With the annotations module you can turn the hits into highlight annotations with
nexpdf_add_annotation. See Annotations.
Redact every match
To remove the matches permanently instead, use nexpdf_redact_matches. See
Redaction.
Scanned documents
Search finds only real text. Run OCR on scanned pages first.