# Javascript: HeaderFooterCollection.add Method

> Adds a new header or footer to a document or to a certain section of the document. If a header or footer is added to the complete document the first section receives the header or footer and all other sections receive headers or footers which are connected to their previous section. To add more than one header or footer a combination of the HeaderFooterType enumeration values can be used.

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

---

### Description

Adds a new header or footer to a document or to a certain section of the document. If a header or footer is added to the complete document the first section receives the header or footer and all other sections receive headers or footers which are connected to their previous section. To add more than one header or footer a combination of the HeaderFooterType enumeration values can be used.

### Syntax

```javascript
<void> HeaderFooterCollection.add(<HeaderFooterType> headerFooterType, [<RequestBooleanCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| headerFooterType | Specifies the headers and/or footers to add. |
| callback | Optional. Receives true, if the header or footer could be added. Otherwise it is false. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example adds a primary header and configures its distance from the page edge.

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

TXTextControl.headersAndFooters.add(TXTextControl.HeaderFooterType.Header, function(added) {
    if (!added) {
        console.warn("The header already exists or cannot be added here.");
        return;
    }

    TXTextControl.headersAndFooters.getItem(
        TXTextControl.HeaderFooterType.Header,
        function(header) {
            header.setDistance(720, function() {
                console.log("Header added with a half-inch distance.");
            }, onTxError);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [HeaderFooterCollection Object](https://docs.textcontrol.com/ds-server/reference/javascript/headerfootercollection/llms-full.txt)
- **Next:** [Javascript: HeaderFooterCollection.getItem Method](https://docs.textcontrol.com/ds-server/reference/javascript/headerfootercollection/getitem-method/llms-full.txt)
