This topic describes how to check whether a document has comments, obtain comments, show or hide comments, and delete all comments when you use a text document.
Check whether a document has comments
Check whether a document has comments.
Syntax
Expression.ActiveDocument.HasComments()Expression: the document type application object.
Return value
Returns a value of the
booleantype.trueindicates that the document has comments.falseindicates that the document has no comments.Example
async function example() { await instance.ready(); const app = instance.Application; // Check whether the document has comments. const hasComments = await app.ActiveDocument.HasComments(); console.log(hasComments); // The return value is true or false. }
Obtain comments
Obtain the comments of a document.
Syntax
Expression.ActiveDocument.GetComments({ Offset, Limit })Expression: the document type application object.
Parameters
ImportantBecause text documents use liquid layout, it takes a long time to obtain the comments of a large document when you specify a large value for
Limitor Offset, or both. In this case, we recommend that you add aloadingtransition effect.Parameter
Type
Required
Description
Offset
Number
Yes
The starting position.
Limit
Number
Yes
The maximum number of comments that can be returned.
Return value
Array.<Object>The following table describes the parameters in the return value.
Parameter
Type
Description
auth
String
The user who added the comment.
content
String
The comment content.
date
Date
The time when the comment was added.
Example
async function example() { await instance.ready(); const app = instance.Application; // Obtain comments. const operatorsInfo = await app.ActiveDocument.GetComments({ Offset: 0, Limit: 20 }); console.log(operatorsInfo); }
Show or hide the comments
Show or hide the comments of a document.
Syntax
Expression.ActiveDocument.ActiveWindow.View.ShowComments = BooleanExpression: the document type application object.
If you set
Booleantotrue, the comments are displayed. If you setBooleantofalse, the comments are hidden.Example
async function example() { await instance.ready(); const app = instance.Application; // Hide the document comments. app.ActiveDocument.ActiveWindow.View.ShowComments = false; }
Delete all comments
Delete all comments in a document.
Syntax
Expression.ActiveDocument.DeleteAllComments()Expression: the document type application object.
Example
async function example() { await instance.ready(); const app = instance.Application; // Delete all comments in the document. await app.ActiveDocument.DeleteAllComments(); }