Text extraction ​
Foxit PDF SDK for Web can extract document text, single-page text, text in a region, and per-character information. Related APIs include:
PDFDoc.getText()PDFPage.getText()PDFPage.getTextInRect()PDFPage.getCharCount()PDFPage.getCharInfoByIndex()PDFPage.getCharRange()PDFPage.getCharInfoAtPoint().
To find keywords in a document and obtain match rectangles, use PDFDoc.searchText() or getTextSearch() in Text search. This page covers sequential text readout, region selection, and character-level geometry.
Text extraction suits content analysis, proofreading, region pick-up, batch processing, or syncing text with business systems.
Extract document text ​
PDFDoc.getText(pages) extracts text over a page range. It returns TaskProgress; use onProgress for progress and segment text (field names depend on the callback). You do not await a single full string directly.
const pdfDoc = pdfViewer.getCurrentPDFDoc();
const progress = pdfDoc.getText([[0, 2]]);
const removeListener = progress.onProgress((data) => {
console.log(data.percent);
if (data.content !== undefined) {
console.log(data.content);
}
});
// Unsubscribe when done and end the task if needed
removeListener();NOTE
PDFDoc.getText() does not support XFA documents (the implementation throws on XFA). For XFA forms, use form APIs. Extraction requires document extract permission.
Extract single-page text ​
const page = await pdfDoc.getPageByIndex(0);
const text = await page.getText();
console.log(text);For structured line breaks with options such as minimum width, use PDFPage.getTexts() (see API Reference).
Extract text in a region ​
PDFPage.getTextInRect(rect, type) extracts text inside a PDF-coordinate rectangle. Optional type: 0 page and field text, 1 page only, 2 fields only; default 0.
The return value is { pageText, fieldsText } (fieldsText is an array of field entries), not a plain string.
const page = await pdfDoc.getPageByIndex(0);
const { pageText, fieldsText } = await page.getTextInRect({
left: 100,
right: 300,
top: 720,
bottom: 680
}, 0);NOTE
getTextInRect()uses PDF coordinates, not Viewer device pixels—the same system asmarkRedactAnnotin Redaction.- Throws on static XFA (similar to the XFA limit on
PDFDoc.getText()). - Requires document extract permission.
Per-character text information ​
From 11.1.0, PDFPage exposes character indexing—useful for proofreading, annotation anchors, and pairing with TextSearchMatch from Text search (e.g. getCharInfoByIndex after a hit).
const page = await pdfDoc.getPageByIndex(0);
const charCount = await page.getCharCount();
for (let i = 0; i < charCount; i++) {
const charInfo = await page.getCharInfoByIndex(i);
console.log(charInfo);
}Character index ranges in a region ({ start, end }[]):
const charRange = await page.getCharRange({
left: 100,
right: 300,
top: 720,
bottom: 680
});At a PDF point, use PDFPage.getCharInfoAtPoint(point, tolerance) with point as [x, y] and tolerance e.g. 0–30.
Notes ​
- Page index starts at
0. - Results depend on extractable text in the PDF; scanned pages usually need OCR first.
- Regions and character geometry use PDF coordinates, not device pixels used for snapshots or rendering.
- For large documents, process by page or page range;
PDFDoc.getText()supports progress callbacks. - Character and region APIs need extract or extract for accessibility permission as implemented.