EditTextToolApi
The Edit Text tool, drivable from code. This is the one that replaces DOM puppeteering outright.
Every member needs the tool to be active (await viewer.activateTool('editText') first) and the edit-text feature; beginEdit, and setText with any text but '', also need extract. A page is analyzed on demand, so editing does not depend on what the user happens to have scrolled into view. Text set this way travels the same path as typing, so font substitution, reflow, and undo all behave identically.
A tool handle throws SDKError INVALID_STATE, with instructions, when its tool is not running, rather than failing silently: "The editText tool is not active. Call viewer.activateTool('editText') and await it first."
commit() and cancel() both deactivate the tool, exactly as pressing Save or Escape in the toolbar does, because committing rewrites and reloads the page. Re-activate before further edits, and treat every block id from before a commit as stale — ids are only stable within one detection pass.
Usage
await viewer.activateTool('editText'); const editText = viewer.tools.editText; const blocks = await editText.listBlocks(0); const total = blocks.find((b) => b.text.startsWith('Total:')); if (total) { await editText.setText(total.id, 'Total: $1,299.00'); await editText.commit(); }
Reading
EditableTextBlock[]. Each block's text is '' under a license without extract.| Parameter | Type | Description |
|---|---|---|
| pageIndex | number | Zero-based page index. |
Promise<EditableTextBlock[]> Each { id, pageIndex, text, bounds, fontFamily, fontSize, fontWeight, isItalic, fillColor, opacity }; id is stable within one detection pass, text includes an uncommitted edit, bounds is a Rect in page space.INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.INVALID_ARGUMENTfor a page index the document has not.PAGE_ERRORwhen the page could not be loaded.
const blocks = await viewer.tools.editText.listBlocks(0);
null.string | null INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.
null.string | null INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.
beforeunload warning beside hasUnsavedChanges; false while the tool is not active.boolean window.addEventListener('beforeunload', (e) => { if (viewer.hasUnsavedChanges || viewer.tools.editText.hasPendingEdits) e.preventDefault(); });
Editing
edit-text and extract: the editor shows the block's words in the page.| Parameter | Type | Description |
|---|---|---|
| blockId | string | A block id from listBlocks() of the current detection pass. |
Promise<void> INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.FEATURE_NOT_LICENSEDwithoutextract.INVALID_ARGUMENTfor a text block id that names no block.PAGE_ERRORwhen the block's page could not be loaded.
const [first] = blocks; if (first) await viewer.tools.editText.beginEdit(first.id);
extract only that is allowed; retyping rejects with FEATURE_NOT_LICENSED, as it opens the block. A block read as right-aligned — an amount in a column, a heading over values set flush under it — keeps its right edge and grows to the left, exactly as when typed.| Parameter | Type | Description |
|---|---|---|
| blockId | string | A block id from listBlocks() of the current detection pass. |
| text | string | The new text; '' removes the block. |
Promise<void> INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.INVALID_ARGUMENT, the text left as it was, when it holds a character no available font can draw; or for a block id that names no block.FEATURE_NOT_LICENSEDwithoutextractfor any text but''.INVALID_STATEwhen other blocks keep being opened while it waits for fonts (a text block that kept losing its editing surface to another).PAGE_ERRORwhen the block's page could not be loaded.
await viewer.tools.editText.setText(total.id, 'Total: $1,299.00'); await viewer.tools.editText.setText(footnote.id, ''); // removes the block
listBlocks() — every block id from before a commit is stale.Promise<void> INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.
await viewer.tools.editText.commit();
Promise<void> Resolves once discarded.INVALID_STATEwhile the tool is not active — withoutedit-textit cannot be activated.
await viewer.tools.editText.cancel();