Skip to Content
NexPDF

Search

Find text in a PDF on the device with NexPDF for React Native and get the page and rectangle of every match.

English

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:

FieldMeaning
page0-based page index
contextThe text around the match
llx, lly, urx, uryThe 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();   // base64

Redact 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.

On this page