Skip to main content

ReplaceCurrentImage

Replaces the current image with an image specified.

Syntax​

expression.ReplaceCurrentImage(sImageUrl, Width, Height);

expression - A variable that represents a ApiDocument class.

Parameters​

NameRequired/OptionalData typeDefaultDescription
sImageUrlRequiredstringThe image source where the image to be inserted should be taken from (currently, only internet URL or Base64 encoded images are supported).
WidthRequiredEMUThe image width in English measure units.
HeightRequiredEMUThe image height in English measure units.

Returns​

boolean

Example​

Replace the selected image with a different image by URL in a document.

// How do I swap out an image for another one in a document?

// Insert an image, select it, then substitute it with a new source to update visuals in a document.

let doc = Api.GetDocument();
let paragraph = doc.GetElement(0);
let drawing = Api.CreateImage(
'https://static.onlyoffice.com/assets/docs/samples/img/presentation_sky.png',
60 * 36000, 60 * 36000
);
paragraph.AddDrawing(drawing);
drawing.Select();
doc.ReplaceCurrentImage('https://static.onlyoffice.com/assets/docs/samples/img/onlyoffice_logo.png');