Skip to main content

GetElementsCount

Returns a number of elements in the current document.

Syntax​

expression.GetElementsCount();

expression - A variable that represents an ApiRichContent class.

Parameters​

This method doesn't have any parameters.

Returns​

number

Example​

Find out how many paragraphs are in formatted text in a PDF.

// How do I count the text elements in rich content in a PDF?

// Check the total number of paragraphs inside formatted content in a PDF.

let doc = Api.GetDocument();
let freeTextAnnot = Api.CreateFreeTextAnnot([160, 50, 360, 135]);
let page = doc.GetPage(0);
page.AddObject(freeTextAnnot);
freeTextAnnot.SetIntent("freeTextCallout");
freeTextAnnot.SetCallout([{x: 161, y: 51}, {x: 249, y: 125}, {x: 261, y: 125}]);
freeTextAnnot.SetRectDiff([100, 64, 0.5, 0.5]);

let richContent = freeTextAnnot.GetContent();
console.log(`Elements count is: ${richContent.GetElementsCount()}`);