Class: CommentManager

Core.Document.OfficeEditor. CommentManager


new CommentManager()

Manages comments within an Office Editor document.
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();

Methods


addCommentReply(parentId, message [, author])

Adds a reply to an existing comment thread in an Office Editor document.
Parameters:
Name Type Argument Description
parentId number The id of the comment thread.
message string The reply message. Empty strings are allowed.
author string <optional>
Optional author name. Defaults to the current user or 'Guest'.
Returns:
Type
Promise.<void>
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
await commentManager.addCommentReply(0, 'comment reply message'); // adds reply to comment with ID 0
await commentManager.addCommentReply(0, 'comment reply message', 'John'); // adds reply with author name

addCommentThreadAtCurrentRange(message [, author])

Adds a new comment thread associated with the current selection in an Office Editor document.
Parameters:
Name Type Argument Description
message string The comment message. Empty strings are allowed.
author string <optional>
Optional author name. Defaults to the current user or 'Guest'.
Returns:
Type
Promise.<void>
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
await commentManager.addCommentThreadAtCurrentRange('Needs review'); // Uses current user or Guest by default
await commentManager.addCommentThreadAtCurrentRange('Needs review', 'John');

deleteComment(id)

Deletes a comment thread or reply in an Office Editor document.
Parameters:
Name Type Description
id number The id of the comment to delete.
Returns:
Type
Promise.<void>
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
await commentManager.deleteComment(0); // deletes comment with ID 0

getComments()

Returns an array of primary comment thread objects in the document. Each comment thread represents a top-level comment and contains all of its replies nested within the replies property.
See:
Returns:
A promise that resolves to an array of primary comment thread objects. Each object contains the thread's id, author, date, message, an array of replies, and a getPagePositions method to retrieve the page location of the comment highlight.
Type
Promise.<Array.<Core.Document.OfficeEditor.CommentManager.Comment>>
Examples
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
const comments = await commentManager.getComments();
for (const comment of comments) {
  console.log(comment.id, comment.author, comment.message);
  for (const reply of comment.replies) {
    console.log(reply.id, reply.author, reply.message);
  }
  const positions = await comment.getPagePositions();
}
// Subscribe to comment updates and re-fetch the latest comments
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
let comments = await commentManager.getComments();
instance.Core.documentViewer.getDocument().addEventListener('commentsUpdated', async () => {
  comments = await commentManager.getComments();
});

moveCursorToComment(id)

Moves the main cursor to the start of the comment thread with the given id.
Parameters:
Name Type Description
id number The unique identifier of the comment thread to navigate to.
Returns:
A promise that resolves when the cursor has been moved to the comment location.
Type
Promise.<void>
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
await commentManager.moveCursorToComment(5); // Moves cursor to comment thread with id 5

setCommentMessage(id, message)

Updates the message content of an existing comment in an Office Editor document.
Parameters:
Name Type Description
id number The id of the comment to update.
message string The new message. Empty strings are allowed.
Returns:
Type
Promise.<void>
Example
const commentManager = instance.Core.documentViewer.getDocument().getOfficeEditor().getCommentManager();
await commentManager.setCommentMessage(0, 'Updated comment message'); // updates comment with ID 0

Type Definitions


Comment

Represents a primary comment thread in an Office Editor document, including all replies nested within it.
Type:
  • Object
Properties:
Name Type Description
id number The unique id of the comment thread
author string The author of the comment thread
date Date The date the comment thread was created
message string The message content of the comment thread
replies Array.<Object> The replies within this comment thread
replies[].id number The unique id of the reply
replies[].parentId number The id of the parent comment thread
replies[].author string The author of the reply
replies[].date Date The date the reply was created
replies[].message string The message content of the reply
getPagePositions function Returns a promise that resolves to an array of objects containing {pageNumber: number, rect: Core.Math.Rect} for each annotation related to the comment thread.