Skip to main content
static replaceElements(NOTEPath: string, page: number, elements: Element[]): Promise<APIResponse<boolean>>;
Parameters
ParameterTypeDescription
NOTEPathstringNOTE/DOC file path
pagenumberPage index (starts from 0)
elementsElement[]Element data array
Returns

Example

import { PluginFileAPI, PluginCommAPI, ElementType, type Element } from 'sn-plugin-lib';

/**
 * Example: read page elements and write back (replace).
 */
export async function exampleReplaceElements() {
 const NOTEPath = '/storage/emulated/0/Note/demo.note';
 const page = 0;

 const listRes = await PluginFileAPI.getElements(page, NOTEPath);
 if (!listRes.success) {
 throw new Error(listRes.error?.message ?? 'getElements call failed');
 }

 const elements = (listRes.result ?? []) as Element[];

 const createRes = await PluginCommAPI.createElement(ElementType.TYPE_TEXT);
 if (!createRes.success) {
 throw new Error(createRes.error?.message ?? 'createElement call failed');
 }
 const textEl = createRes.result as Element;
 if (textEl.textBox) {
 textEl.textBox.textContentFull = 'Replaced content';
 textEl.textBox.fontSize = 16;
 textEl.textBox.textBold = 1;
 textEl.textBox.textAlign = 1;
 textEl.textBox.textRect = { left: 100, top: 120, right: 600, bottom: 220 };
 }

 const newElements = [textEl];
 const res = await PluginFileAPI.replaceElements(NOTEPath, page, newElements);
 if (!res.success) {
 throw new Error(res.error?.message ?? 'replaceElements call failed');
 }
 return res.result;
}