Skip to main content

SetText

Replaces all content of the current document content object with the specified text, preserving the formatting of the first paragraph.

Syntax

expression.SetText(text);

expression - A variable that represents a ApiDocumentContent class.

Parameters

NameRequired/OptionalData typeDefaultDescription
textRequiredstringThe text to set.

Returns

ApiRun

Example

Replace the text of a shape's content in a PDF.

// How do I overwrite all the text inside a shape's document content in a PDF?

// Clear existing text and write a new sentence into a shape's content area in a PDF.

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

const fill = Api.CreateSolidFill(Api.HexColor('#E8D5B7'));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape('roundRect', Api.MillimetersToEmus(300), Api.MillimetersToEmus(130), fill, stroke);
shape.SetPosition(Api.MillimetersToEmus(20), Api.MillimetersToEmus(35));
const docContent = shape.GetContent();
docContent.GetElement(0).AddText('Original shape content text.');
docContent.SetText('Updated shape content text.');
const infoParagraph = Api.CreateParagraph();
infoParagraph.AddText('Text from document content: ' + docContent.GetText());
docContent.Push(infoParagraph);
page.AddObject(shape);