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 parentIdnumber The id of the comment thread. messagestring The reply message. Empty strings are allowed. authorstring <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 messagestring The comment message. Empty strings are allowed. authorstring <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 idnumber 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
repliesproperty.- See:
-
- commentsUpdated fired whenever comments are added, removed, or modified.
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 idnumber 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 idnumber The id of the comment to update. messagestring 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 idnumber The unique id of the comment thread authorstring The author of the comment thread dateDate The date the comment thread was created messagestring The message content of the comment thread repliesArray.<Object> The replies within this comment thread replies[].idnumber The unique id of the reply replies[].parentIdnumber The id of the parent comment thread replies[].authorstring The author of the reply replies[].dateDate The date the reply was created replies[].messagestring The message content of the reply getPagePositionsfunction 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.