DS Server

Javascript: TXTextControl.loadDocument Method

Method|Introduced in 23.0

Description

Loads text in a certain format. The complete contents of the web editor are replaced.

Syntax

<void> TXTextControl.loadDocument(<StreamType> streamType, <string> base64Data, <LoadDocumentCallback> callback, [<LoadSettings> loadSettings], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
streamType

Specifies one of the numerical StreamType values.

base64Data

Base64 encoded document data. For encoding strings containing characters outside of the Latin1 range use TXTextControl.btoaUTF8.

callback

Receives information about the loaded data when the loading is finished.

loadSettings

Optional. Additional settings for loading the data.

errorCallback

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

Examples

The following example shows how to load a short unicode HTML snippet into the web editor.

var html = "<h3>This is some <em>HTML</em> text. Стоял он, дум великих полн, И вдаль глядел.</h3>";
var encoded = TXTextControl.btoaUTF8(html);
TXTextControl.loadDocument(TXTextControl.StreamType.HTMLFormat, encoded);

The following example demonstrates TXTextControl.loadDocument in a practical document-editing workflow. It loads text in a certain format. The complete contents of the web editor are replaced.

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

TXTextControl.loadDocument(
    TXTextControl.StreamType.HTMLFormat,
    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAFgAH/qbPzWQAAAABJRU5ErkJggg==",
    function(result) {
        if (!result) {
            console.warn("No load document callback data was returned.");
            return;
        }
        
        console.log("load document result:", result);
    },
    { loadImages: true, loadHypertextLinks: true },
    onTxError
);