Javascript: TextFrameCollection.addAnchoredAtLocation Method
Description
Inserts a new text frame which is anchored to the specified text position. It has the specified location relative to the paragraph it is anchored to and a textflow which is given through the insertionMode parameter. Anchored text frame are moved with the text.
Syntax
<void> TextFrameCollection.addAnchoredAtLocation(<Size> size, <Point> location, <number> textPosition, <TextFrameInsertionMode> insertionMode, [<RequestTextFrameCallback> callback], [<ErrorCallback> errorCallback])Parameters
| Parameter | Description |
|---|---|
| size | The text frame's size in twips. |
| location | Specifies the location, in twips, at which the text frame is to be inserted. This is a location relative to the top left corner either of a page or of a paragraph. |
| textPosition | Specifies the text position at which the text frame is to be inserted. If -1 is specified, the text frame is inserted at the current input position. |
| insertionMode | Specifies how the text flow is handled. |
| callback | Optional. The newly created text frame object is returned via this callback function. |
| errorCallback | Optional. Is called when the operation failed with an error. |
Examples
The following example demonstrates TextFrameCollection.addAnchoredAtLocation in a practical document-editing workflow. It inserts a new text frame which is anchored to the specified text position. It has the specified location relative to the paragraph it is anchored to and a textflow which is given through the insertionMode parameter. Anchored text frame are moved with the text.
function onTxError(error) {
console.error("TX Text Control error:", error.msg);
error.handled = true;
}
TXTextControl.textFrames.addAnchoredAtLocation(
{ width: 2880, height: 1440 },
{ x: 1440, y: 720 },
-1,
TXTextControl.TextFrameInsertionMode.AsCharacter,
function(textFrame) {
if (!textFrame) {
console.warn("No text frame was returned.");
return;
}
console.log("add anchored at location result:", textFrame);
},
onTxError
);