DS Server

Javascript: BarcodeCollection.addAnchored Method

Method|Introduced in 28.0

Description

Creates and inserts a new barcode 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 barcodes are moved with the text.

Syntax

<void> BarcodeCollection.addAnchored(<RequestBarcodeFrameCallback> callback, [<ErrorCallback> errorCallback], <BarcodeType> barcodeType, <string> text, <HorizontalAlignment> horizontalAlignment, <number> textPosition, <FrameInsertionMode> insertionMode)

Parameters

ParameterDescription
callback

The newly created barcode object is returned via this callback function.

errorCallback

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

barcodeType

The barcode type.

text

The text the barcode should encrypt.

horizontalAlignment

Specifies the barcode's horizontal alignment.

textPosition

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

insertionMode

Specifies how the text flow is handled.

Examples

The following example demonstrates BarcodeCollection.addAnchored in a practical document-editing workflow. It creates and inserts a new barcode 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 barcodes are moved with the text.

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

function addAnchored(barcodeType) {
    TXTextControl.barcodes.addAnchored(
        function(barcodeFrame) {
            if (!barcodeFrame) {
                console.warn("No barcode frame was returned.");
                return;
            }
            
            console.log("add anchored result:", barcodeFrame);
        },
        onTxError,
        barcodeType,
        "Quarterly report",
        TXTextControl.HorizontalAlignment.Center,
        -1,
        TXTextControl.FrameInsertionMode.AsCharacter
    );
}