Skip to main content
TextBox can only be inserted into the main layer. This API supports undo/redo in NOTE.
static insertText(textBox: {
 fontSize?: number;
 fontPath?: string;
 textContentFull: string;
 textRect: Rect;
 textAlign?: number;
 textBold?: number;
 textItalics?: number;
 textFrameWidthType?: number;
 textFrameStyle?: number;
 textEditable?: number;
}): Promise<APIResponse<boolean>>;
Parameters
ParameterTypeDescription
textBox.textContentFullstringText content (required, non-empty)
textBox.textRectRectTextBox rectangle (required; must be non-zero area)
textBox.fontSizenumberFont size (must be positive)
textBox.fontPathstringFont path (optional)
textBox.textAlignnumberAlignment: 0 left, 1 center, 2 right
textBox.textBoldnumberBold: 0 normal, 1 bold
textBox.textItalicsnumberItalic: 0 normal, 1 italic
textBox.textFrameWidthTypenumberBorder width type: 0 fixed width, 1 auto width
textBox.textFrameStylenumberBorder style: 0 none, 3 stroke
textBox.textEditablenumberEditable: 0 editable, 1 non-editable
Returns

Example

import { PluginNoteAPI, type Rect } from 'sn-plugin-lib';

/**
 * Insert TextBox example.
 */
export async function exampleInsertText() {
 const textRect: Rect = { left: 100, top: 100, right: 320, bottom: 180 };
 const res = await PluginNoteAPI.insertText({
 textContentFull: 'Hello from plugin',
 textRect,
 fontSize: 32,
 textAlign: 0,
 textBold: 0,
 textItalics: 0,
 textFrameWidthType: 0,
 textFrameStyle: 0,
 textEditable: 0,
 });

 if (!res.success) {
 throw new Error(res.error?.message ?? 'insertText call failed');
 }
 return res.result;
}