Skip to content

Documentation

JavaScript SDK: Document: text and tables

Document holds the parsed file. Check complete() and warnings() before processing everything. The methods below run locally.

Each example is a separate fragment inside async function run(ctx). Use await only for methods whose signature returns a Promise.

Obtaining the object

const document = await ctx.documents().fromBytes('sku,price\nA-1,1250', 'report.csv');

Methods

text

document.text() → string

The document text, including available Office headers, footers, and notes. PDF text stays divided by page. DOCX structure and formatting are also available through blocks().

const result = document.text();

format

document.format() → string

The detected format, such as xlsx, docx, pdf, or csv.

const result = document.format();

tables

document.tables() → Array<object>

Excel sheets or Word tables, each with name and rows. Excel numbers remain numbers. Supported XLSX formulas are calculated locally with xlcalculator. External references and macros are never executed. rows() and cell() return the calculated result, formula() returns the original expression, and cachedValue() returns the value saved by the document author. Use error() and calculation() to inspect calculation problems.

const result = document.tables();

rows

document.rows(sheet) → Array<Array<unknown>>

Returns rows of the selected sheet by index or name. Missing sheets return an empty array. For PDF, use pages() or text().

const result = document.rows();

pages

document.pages() → Array<object>

PDF pages with number, text, and ocr. Scanned pages are recognized locally in Russian and English. One parse is limited to five image pages and 100 text pages.

const result = document.pages();

links

document.links() → Array<unknown>

Links found in the document. The document service does not follow them or download external images. If needed, explicitly request an allowed link through the network SDK.

const result = document.links();

complete

document.complete() → boolean

Returns false if an extraction limit was reached. Check it before saving what should be a complete report. Limits: 20 sheets or tables, 5,000 rows, 100 columns, 50,000 cells in total, and 1 MiB of text.

const result = document.complete();

warnings

document.warnings() → Array<unknown>

Codes describing parsing limits or special cases: cached formula values, older Office formats, images in Word or Excel, and OCR limits. Extraction from older DOC/XLS files is limited; embedded objects are not executed.

const result = document.warnings();

sheetNames

document.sheetNames() → Array<string>

Names of extracted sheets or tables in their original order. Empty for PDFs and images.

const result = document.sheetNames();

sheet

document.sheet(sheet) → Worksheet

Select a sheet by zero-based index or exact name. Returns a Worksheet. A missing sheet raises a clear error; rows() keeps its earlier behavior and returns an empty array. Worksheet methods run locally without reading the file again.

const result = document.sheet();

page

document.page(number) → string

Text from a PDF or raster-image page, using a one-based page number. A missing page returns an empty string; an invalid number raises an error. Use text() for Word documents.

const result = document.page(2);

matches

document.matches(pattern, limit) → Array<Array<string>>

Finds matches using a JavaScript regular expression. Returns arrays of matches and capture groups; PCRE syntax is not used.

const result = document.matches('/(\\d+)/');

chunks

document.chunks(characters, overlap) → Array<unknown>

Split text into Unicode-character fragments. characters must be 100–16,000, and overlap must be between 0 and characters - 1. This method does not send fragments to external services. Do not pass private fragments to analyze() or transform() without a separate data-processing policy.

const result = document.chunks();

blocks

document.blocks() → Array<unknown>

DOCX paragraphs and table references in document order. A paragraph includes kind=paragraph, heading level, align, indent, before, after, marker, depth, and runs. Each run has text, bold, italic, underline, and point size. A kind=table block contains the table's index in tables(). Other formats return an empty array. Values are not sent to an external model.

const result = document.blocks();