Skip to main content

AddComment

Adds a comment to the current slide.

Syntax

expression.AddComment(posX, posY, text, author, userId);

expression - A variable that represents a ApiSlide class.

Parameters

NameRequired/OptionalData typeDefaultDescription
posXRequirednumberThe X position (in EMU) of the comment (defaults to 0).
posYRequirednumberThe Y position (in EMU) of the comment (defaults to 0).
textRequiredstringThe comment text.
authorOptionalstringThe author's name (defaults to the current user name).
userIdOptionalstringThe user ID of the comment author (defaults to the current user ID).

Returns

boolean

Example

Add comments to a slide with author and user ID information.

// Create multiple comments with different properties and retrieve all comments from the presentation.

// Display the comment details including text, author name, and user ID in a shape.

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

const commentText = "Note: check method to add comments to slides.";
const commentAuthor = "Mark Pottato";
const commentUserId = "user-42";
const posX = 20 * 36000;
const posY = 20 * 36000;

slide.AddComment(posX, posY, commentText, commentAuthor, commentUserId);
slide.AddComment(posX, posY, 'Author for this comment was not specified');

const fill = Api.CreateSolidFill(Api.RGB(50, 100, 150));
const stroke = Api.CreateStroke(0, Api.CreateNoFill());
const shape = Api.CreateShape("rect", 300 * 36000, 150 * 36000, fill, stroke);
const paragraph = shape.GetDocContent().GetElement(0);

const comments = presentation.GetAllComments();
for (let i = 0; i < comments.length; i++) {
const comment = comments[i];
paragraph.AddText('Comment' + (i + 1) + ':' + '\n');
paragraph.AddText('Text: ' + comment.GetText() + '\n');
paragraph.AddText('Author: ' + comment.GetAuthorName() + '\n');
paragraph.AddText('User ID: ' + comment.GetUserId() + '\n');
paragraph.AddLineBreak();
}

slide.RemoveAllObjects();
shape.SetPosition(posX, posY);
slide.AddObject(shape);