Search
Find text in a PDF on the device with NexPDF for React Native 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, and resolves to an array of hits:
const hits = await doc.search('termination');
for (const hit of hits) console.log(`page ${hit.page + 1}: ${hit.context}`);Each hit has:
| 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 |
To draw a hit over a rendered page, map its rectangle with the page's
PageView.
Highlight every match
With the annotations module, addHighlight(page, rect, color?) turns each hit into a highlight
annotation (the colour defaults to #FFD400):
for (const hit of await doc.search('termination')) {
await doc.addHighlight(hit.page, [hit.llx, hit.lly, hit.urx, hit.ury]);
}
const pdf = await doc.saveBytes(); // base64Redact every match
To remove the matches permanently instead, use redactMatches. See
Redaction.
Scanned documents
Search finds only real text. Run OCR on scanned pages first.