> ## Documentation Index
> Fetch the complete documentation index at: https://revise.io/developer/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Documents

> Opening, switching, and closing documents in a multi-document workspace.

## Open a document

A document is a `File`, `Blob`, or `ArrayBuffer` in any of the [supported
formats](/developer/docs/developer/docs/editor-sdk/guides/formats). Pass documents in `initialDocuments`, or
open them at runtime:

```ts theme={null}
const doc = await editor.documents.open(
  { id: "exhibit-a", title: "Exhibit A", source: file },
  { activate: true },
);
```

`open()` resolves to a `ReviseDocumentHandle` when the document is parsed and
ready. A new document becomes active by default. Pass `{ activate: false }` to
open it in the background.

<Warning>
  You assign document IDs. Each must be stable and unique within one editor
  instance. Callbacks, tool routing, and `forDocument()` use them. Do not reuse
  an ID for different content.
</Warning>

### Per-document options

Any editor-wide option can be overridden per document:

```ts theme={null}
await editor.documents.open({
  id: "exhibit-a",
  source: file,
  format: "markdown", // optional; inferred from the filename or MIME type
  title: "Exhibit A",
  documentMode: "suggesting",
  readOnly: false,
  zoom: "fit-width",
  defaultCommentsOpen: false,
  agent: { model: "claude-opus-5-5" },
});
```

## Switch and close

```ts theme={null}
editor.documents.activate("exhibit-a");
editor.documents.close("exhibit-a");
editor.documents.getActiveId(); // "contract-1"
editor.documents.list();        // [{ id, title, status, active, error }]
```

Closing a document does not save it. Export it first if you need the file.

## Observe the document list

```ts theme={null}
useEffect(
  () =>
    editor.documents.subscribe((state) => {
      setTabs(state.documents);
      setActiveId(state.activeDocumentId);
    }),
  [editor],
);
```

Each entry has a `status` of `"opening"`, `"ready"`, or `"error"`, and an
`error` string when parsing failed. Use them to render tabs with loading and
error states.

## Controlled or uncontrolled

By default, the component tracks the active document. To control it from your
own state, pass `activeDocumentId` and handle `onActiveDocumentChange`:

```tsx theme={null}
<ReviseEditor
  activeDocumentId={activeId}
  onActiveDocumentChange={setActiveId}
  initialDocuments={docs}
/>
```

`defaultActiveDocumentId` sets the initial active document without controlling it.

## Export

```ts theme={null}
const blob = await editor.tools.exportDocx();               // active document
const other = await editor.tools.exportDocx("exhibit-a");   // a specific one
```

## Read content

Read the document tree for your own logic, such as word counts, validation, or
autosave:

```ts theme={null}
const doc = editor.getDocument();          // active
const doc2 = editor.getDocument("exhibit-a");
```

`onChange(documentId, document)` fires on every edit from the user, your
toolbar, or an agent.

<Tip>
  `onChange` fires on every keystroke. Debounce before saving. Use
  `measure_document` or a cheap check instead of walking the whole tree on
  every call.
</Tip>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.