Web SDKv1.0.0

TextApi

Reading and searching text. Both members need the extract feature and refuse with FEATURE_NOT_LICENSED without it. To _change_ text, use viewer.tools.editText.

This search is distinct from viewer.search(): that one drives the search UI and highlights matches on screen, while this one returns data and needs no viewer at all. Each match carries rects, the rectangles it covers, as Rects in page space; a match broken across lines has one rectangle per line, which is why it is not a single box. Extraction order follows the order in which the page content draws the text. That usually matches reading order, but a PDF carries no guarantee of one.

namespacedoc.text

Usage

TypeScript
const hits = await doc.text.search('Invoice', { matchCase: true, limit: 50 });

for (const hit of hits) {
  console.log('page ' + (hit.pageIndex + 1) + ': ' + hit.text);
}

Text

extractmethodsince 1.0.0
extract(pageIndex: number): Promise<string>
All text on a page, as a string; lines end with \n. Needs the extract feature.
ParameterTypeDescription
pageIndexnumberZero-based page index.
Returns Promise<string> Lines end with \n.
  • INVALID_ARGUMENT — a page index out of range.
  • PAGE_ERROR — the page or its text could not be loaded.
  • DOCUMENT_CLOSED — the document has been closed.
  • FEATURE_NOT_LICENSED — the license lacks extract.
TypeScript
const pages = [];
for (let i = 0; i < doc.pageCount; i++) pages.push(await doc.text.extract(i));