# Javascript: TextPartCollection.getMainText Method

> Gets the main text part of the document.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: TextPartCollection.getMainText Method
- **349 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/getmaintext-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/getmaintext-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/getmaintext-method/llms-full.txt

---

### Description

Gets the main text part of the document.

### Syntax

```javascript
<void> TextPartCollection.getMainText([<RequestTextPartCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| callback | Optional. Receives the main text textpart object. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `TextPartCollection.getMainText` in a practical document-editing workflow. It gets the main text part of the document.

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

TXTextControl.textParts.getMainText(
    function(textPart) {
        if (!textPart) {
            console.warn("No formatted text was returned.");
            return;
        }
        
        console.log("get main text result:", textPart);
    },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: TextPartCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/textpartcollection/getitem-method/llms-full.txt)
- **Next:** [TextPastedCallback Function](https://docs.textcontrol.com/ds-server/reference/javascript/textpastedcallback/llms-full.txt)
