TX Text Control .NET Server

Javascript: HeaderFooterCollection.add Method

Method|Introduced in 28.0

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

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

Parameters

ParameterDescription
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.

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);