# Javascript: TableOfContents.save Method

> Saves the TableOfContents in a certain format and sends the result back asynchronously by calling a given callback function.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 29.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: TableOfContents.save Method
- **503 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tableofcontents/save-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tableofcontents/save-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/tableofcontents/save-method/llms-full.txt

---

### Description

Saves the TableOfContents in a certain format and sends the result back asynchronously by calling a given callback function.

### Syntax

```javascript
<void> TableOfContents.save(<StreamType> streamType, <SaveDocumentCallback> callback, [<SaveSettings> saveSettings], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| streamType | Specifies one of the StreamType values. |
| callback | Receives the TableOfContents's data in a certain format including additional information. |
| saveSettings | Optional. Specifies additional settings for saving. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TableOfContents.save` in a practical document-editing workflow. It saves the TableOfContents in a certain format and sends the result back asynchronously by calling a given callback function.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

function save(tableOfContents) {
    tableOfContents.save(
        TXTextControl.StreamType.HTMLFormat,
        function(result) {
            if (!result) {
                console.warn("No save document result was returned.");
                return;
            }
            
            console.log("save result:", result);
        },
        { creatorApplication: "Document Editor sample" },
        onTxError
    );
}
```

---

## Nearby

- **Previous:** [Javascript: TableOfContents.getTitle Method](https://docs.textcontrol.com/ds-server/reference/javascript/tableofcontents/gettitle-method/llms-full.txt)
- **Next:** [Javascript: TableOfContents.scrollTo Method](https://docs.textcontrol.com/ds-server/reference/javascript/tableofcontents/scrollto-method/llms-full.txt)
