TX Text Control .NET Server

Javascript: Paragraph.setFormattingStyle Method

Method|Introduced in 28.0

Description

Sets the paragraph's formatting style. The specified style must be the name of a style contained in the ParagraphStyles collection of a Text Control document.

Syntax

<void> Paragraph.setFormattingStyle(<string> formattingStyle, <EmptyRequestCallback> callback, [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
formattingStyle

The paragraph formatting style.

callback

Is called when the operation completed.

errorCallback

Optional. Is called when the operation failed with an error.

Examples

The following example demonstrates Paragraph.setFormattingStyle in a practical document-editing workflow. It sets the paragraph's formatting style. The specified style must be the name of a style contained in the ParagraphStyles collection of a Text Control document.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const paragraphs = mainText.paragraphs;
    paragraphs.getItem(function(paragraph) {
        if (!paragraph) {
            console.warn("No paragraph is available at the current input position.");
            return;
        }
    
        paragraph.setFormattingStyle(
            "MM/dd/yyyy",
            function() {
                console.log("set formatting style completed.");
            },
            onTxError
        );
    }, onTxError);
}, onTxError);