Skip to main content

AddElement

Adds an element to the current paragraph.

Syntax​

expression.AddElement(oElement, nPos);

expression - A variable that represents a ApiParagraph class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
oElementRequiredParagraphContentThe document element which will be added at the current position. Returns false if the oElement type is not supported by a paragraph.
nPosOptionalnumberThe position where the current element will be added. If this value is not specified, then the element will be added at the end of the current paragraph.

Returns​

boolean

Example​

Insert text content into a paragraph in a PDF.

// How do I add text to a paragraph in a PDF?

// Place a text element within a paragraph to display content 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);

const run = Api.CreateRun();
run.AddText("This is the text for a text run. Nothing special.");
paragraph.AddElement(run);
page.AddObject(shape);