Skip to main content

ReplacePlaceholder

Replaces the placeholder by a drawing on the slide.

Inherited from ApiDrawing.ReplacePlaceholder.

Syntax​

expression.ReplacePlaceholder(drawing);

expression - A variable that represents an ApiShape class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
drawingRequiredDrawingThe drawing object that will replace the placeholder.

Returns​

boolean

Example​

Replace a placeholder with an image in a presentation.

// How do I swap a placeholder for an actual image in a presentation?

// Insert an image into a shape that has a placeholder in a presentation.

const presentation = Api.GetPresentation();
const slide = presentation.GetSlideByIndex(0);
slide.RemoveAllObjects();

const fill = Api.CreateNoFill();
const stroke = Api.CreateStroke(0, Api.CreateNoFill);
const shape = Api.CreateShape('rect', Api.MillimetersToEmus(174), Api.MillimetersToEmus(38), fill, stroke);

const placeholder = Api.CreatePlaceholder('body');
placeholder.SetType('picture');
shape.SetPlaceholder(placeholder);
slide.AddObject(shape);

const shapeCopy = shape.Copy();
shapeCopy.SetPosition(0, Api.MillimetersToEmus(48));
slide.AddObject(shapeCopy);

const image = Api.CreateImage('https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png', Api.MillimetersToEmus(200), Api.MillimetersToEmus(100));
shapeCopy.ReplacePlaceholder(image);