TX Text Control .NET Server

Javascript: ImageCollection.addAnchored Method

Method|Introduced in 28.0

Description

Creates and inserts a new image which is anchored to the specified text position. It has the specified horizontal alignment and a textflow which is given through the insertionMode parameter. Anchored image are moved with the text.

Syntax

<void> ImageCollection.addAnchored(<string> imageData, <HorizontalAlignment> horizontalAlignment, <number> textPosition, <ImageInsertionMode> insertionMode, [<RequestImageCallback> callback], [<ErrorCallback> errorCallback])

Parameters

ParameterDescription
imageData

The base64 encoded image data.

horizontalAlignment

Specifies the image's horizontal alignment.

textPosition

Specifies the text position at which the image is to be inserted. If -1 is specified, the image is inserted at the current input position.

insertionMode

Specifies how the text flow is handled.

callback

Optional. The newly created image object is returned via this callback function.

errorCallback

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

Examples

The following example demonstrates ImageCollection.addAnchored in a practical document-editing workflow. It creates and inserts a new image which is anchored to the specified text position. It has the specified horizontal alignment and a textflow which is given through the insertionMode parameter. Anchored image are moved with the text.

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

TXTextControl.images.addAnchored(
    "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAFgAH/qbPzWQAAAABJRU5ErkJggg==",
    TXTextControl.HorizontalAlignment.Center,
    -1,
    TXTextControl.ImageInsertionMode.AsCharacter,
    function(image) {
        if (!image) {
            console.warn("No image was returned.");
            return;
        }
        
        console.log("add anchored result:", image);
    },
    onTxError
);

Further Reading

  • X15: Inserting Client-Side Images using JavaScript –