跳到主要内容

RemoveElement

使用指定的位置移除元素。

备注

如果移除的元素是段落的最后一个元素(即所有元素都从段落中移除),将自动创建一个新的空 Run。如果要向此 Run 添加内容,请使用 ApiParagraph#GetElement 方法。

语法​

expression.RemoveElement(nPos);

expression - 表示 ApiParagraph 类的变量。

参数​

名称必需/可选数据类型默认值描述
nPos必需number要从段落中移除的元素位置。

返回值​

boolean

示例​

在 PDF 中从段落对象删除特定元素。

// Useful for removing an element by its position in a paragraph in a PDF.

// Eliminate an element at a given index from a paragraph in a PDF.

const doc = Api.GetDocument();
const page = doc.GetPage(0);

const gs1 = Api.CreateGradientStop(Api.RGB(255, 213, 191), 0);
const gs2 = Api.CreateGradientStop(Api.RGB(255, 111, 61), 100000);
const fill = Api.CreateRadialGradientFill([gs1, gs2]);
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("flowChartMagneticTape", 150 * 36000, 65 * 36000, fill, stroke);
shape.SetPosition(608400, 1267200);

const docContent = shape.GetContent();
const paragraph = docContent.GetElement(0);
paragraph.RemoveAllElements();

let run = Api.CreateRun();
run.AddText("Run 1. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.AddText("Run 2. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.AddText("Run 3. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.AddText("Run 4. ");
paragraph.AddElement(run);

run = Api.CreateRun();
run.AddText("Run 5. ");
paragraph.AddElement(run);

paragraph.RemoveElement(3);

page.AddObject(shape);