Skip to Content
NexPDF

Text and the assistant

Select and copy text, ask questions about a document with the assistant, and export its text in an Electron window with NexPDF.

English

License module

Text selection, copying and the assistant are part of the viewer module and work without a key. Exporting to HTML, JSON, XML, CSV or RTF needs the conversion module (Startup tier and above).

Select and copy

In the View mode the user selects text on the page and copies it. Text is extracted in reading order, with the layout reconstructed into lines and paragraphs.

The assistant

The assistant panel answers questions about the open document and cites the pages it used. It runs in two ways:

  • Without a key it finds the most relevant passages in the document, offline.
  • With ANTHROPIC_API_KEY in the engine's environment it writes answers with page citations. The question and the relevant passages are sent to the Anthropic API.
const { startEngine } = require('@nexdevit/nexpdf-electron');

const engine = await startEngine({ license, env: { ANTHROPIC_API_KEY: process.env.ANTHROPIC_API_KEY } });

openPdfWindow passes the main process environment to the engine, so setting process.env.ANTHROPIC_API_KEY before calling it has the same effect. To hide the assistant, hide its panel tab with toolbarConfig.hiddenItems: ["assistant"], or leave ai out of modeConfig.availableModes to drop the Convert mode.

Export the text

The Convert mode exports the document as HTML, CSV, JSON, XML or RTF, as well as Word, Excel and PowerPoint. See Conversion.

Scanned documents

Pages that are images have no text. Run OCR in the Convert mode first.

From code

To extract text in code, without a window, use the document API (openDocumentFile, then doc.text(page) or doc.markdown(); see the Node.js SDK). For tables, label/value pairs and schema extraction, see Structured extraction.

doc.raw.pageWordsJson(page, optionsJson) returns the words of a page with exact boxes, for example to place your own highlights:

const { openDocumentFile } = require('@nexdevit/nexpdf-electron');

const doc = await openDocumentFile('contract.pdf');
const { words } = JSON.parse(doc.raw.pageWordsJson(0, null));
for (const w of words) console.log(w.text, w.bbox, w.font, w.size, w.angle, w.line);
doc.close();

Each word has text, bbox ([llx, lly, urx, ury]), quad (baseline start, baseline end, top end, top start, so it follows rotated text), font, size, angle and line. {"glyphs": true} adds the boxes of each glyph.

On this page