> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/web/annotation/annotationmanager/replies.md).

# Creating replies for PDF annotations

Learn how to create replies for PDF annotations effortlessly with the AnnotationManager. Discover how to leverage the isReply API and getReplies function to manage annotations effectively. Use the cre

Annotating would not be complete without a discussion of the marked content. Annotations in PDFs allows users to reply to an annotation. A reply is actually just another annotation behind the scenes, specifically a [Sticky Note](/web/annotation/annotation-types/stickynoteannotation.md) annotation.

## Reading replies

Since replies are just Sticky Note annotations, they can be found in the annotation list provided by the AnnotationManager. We can leverage the `isReply` API on annotations to differentiate from other annotations. Annotations in WebViewer are also aware of their replies which we can get using `getReplies`.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { documentViewer, annotationManager } = instance.Core;

    documentViewer.addEventListener('annotationsLoaded', () => {
      annotationManager.getAnnotationsList().forEach(annot => {
        if (!annot.isReply()) {
          const replies = annot.getReplies();
          console.log(`- Logging comments for ${annot.Id}`);
          replies.forEach(reply => {
            console.log(`--- ${reply.Id}: ${reply.getContents()}`);
          });
        }
      });
    });
  });
```

{% endcode %}

[DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded) [AnnotationManager.getAnnotationsList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getAnnotationsList) [Annotation.isReply](https://sdk.apryse.com/api/web/Core.Annotations.Annotation.html#isReply) [Annotation.getReplies](https://sdk.apryse.com/api/web/Core.Annotations.Annotation.html#getReplies) [StickyAnnotation.getContents](https://sdk.apryse.com/api/web/Core.Annotations.StickyAnnotation.html#getContents)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { docViewer, annotManager } = instance;

    docViewer.addEventListener('annotationsLoaded', () => {
      annotManager.getAnnotationsList().forEach(annot => {
        if (!annot.isReply()) {
          const replies = annot.getReplies();
          console.log(`- Logging comments for ${annot.Id}`);
          replies.forEach(reply => {
            console.log(`--- ${reply.Id}: ${reply.getContents()}`);
          });
        }
      });
    });
  });
```

{% endcode %}

[DocumentViewer#annotationsLoaded](https://sdk.apryse.com/api/web/Core.DocumentViewer.html#event:annotationsLoaded) [AnnotationManager.getAnnotationsList](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getAnnotationsList) [Annotation.isReply](https://sdk.apryse.com/api/web/Core.Annotations.Annotation.html#isReply) [Annotation.getReplies](https://sdk.apryse.com/api/web/Core.Annotations.Annotation.html#getReplies) [StickyAnnotation.getContents](https://sdk.apryse.com/api/web/Core.Annotations.StickyAnnotation.html#getContents)
{% endtab %}
{% endtabs %}

{% hint style="info" %}
To get the parent from a reply, you can use [AnnotationManager.getRootAnnotation](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#getRootAnnotation).
{% endhint %}

## Creating replies

Creating replies through the AnnotationManager is made easy with the [`createAnnotationReply`](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#createAnnotationReply) API. You only need the annotation you are replying to as well as the reply text.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { Annotations, documentViewer, annotationManager } = instance.Core;

    documentViewer.addEventListener('annotationsLoaded', () => {
      annotationManager.getAnnotationsList().forEach(annot => {
        if (!annot.isReply() && annot instanceof Annotations.RectangleAnnotation) {
          annotationManager.createAnnotationReply(annot, `Viewed on ${new Date()}`);
        }
      });
    });
  });
```

{% endcode %}

[AnnotationManager.createAnnotationReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#createAnnotationReply)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { Annotations, docViewer, annotManager } = instance;

    docViewer.addEventListener('annotationsLoaded', () => {
      annotManager.getAnnotationsList().forEach(annot => {
        if (!annot.isReply() && annot instanceof Annotations.RectangleAnnotation) {
          annotManager.createAnnotationReply(annot, `Viewed on ${new Date()}`);
        }
      });
    });
  });
```

{% endcode %}

[AnnotationManager.createAnnotationReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#createAnnotationReply)
{% endtab %}
{% endtabs %}

## Deleting replies

Since replies are just annotations, deleting replies is the same as [deleting an annotation](/web/annotation/annotationmanager/annotationmanager.md#removing-annotations) with the annotation manager.

## Events

### addReply

When a reply is added, the `addReply` event will be triggered on the AnnotationManager. This may be helpful in sending notifications when a reply is added.

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { annotationManager } = instance.Core;

    annotationManager.addEventListener('addReply', (reply, parent, root) => {
      
    });
  });
```

{% endcode %}

[AnnotationManager#addReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:addReply)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer({...}, viewerElement)
  .then(instance => {
    const { annotManager } = instance;

    annotManager.on('addReply', (reply, parent, root) => {
      
    });
  });
```

{% endcode %}

[AnnotationManager#addReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:addReply)
{% endtab %}
{% endtabs %}

### deleteReply

Suppose we wanted to programmatically have a reply letting the user know that a comment was deleted from the parent annotation. This can be achieved by using the [`createAnnotationReply`](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#createAnnotationReply) method along with the [`deleteReply`](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:deleteReply) listener.

![](https://3532544125-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FX9YnTSKIHvV7m0A36LbO%2Fuploads%2Fgit-blob-1c4f9adfd54c1aafa601613cf56025b23a5ff281%2F99d9999fc760282fa1feebae873b4b193605228d-325x258.gif?alt=media)

{% tabs %}
{% tab title="JavaScript (SDK v8.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(…)
.then(instance => {
	const { annotationManager } = instance.Core;

  annotationManager.addEventListener('deleteReply', (annotation, root) => {
      annotationManager.createAnnotationReply(root, `Comment was Removed by ${annotationManager.getCurrentUser()}`);
  });
});
```

{% endcode %}

[AnnotationManager#deleteReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:deleteReply)
{% endtab %}

{% tab title="JavaScript (SDK v6.0+)" %}
{% code lineNumbers="true" %}

```js
WebViewer(…)
.then(instance => {
	const { annotManager } = instance;

  annotManager.on('deleteReply', (annotation, root) => {
      annotManager.createAnnotationReply(root, `Comment was Removed by ${annotManager.getCurrentUser()}`);
  });
});
```

{% endcode %}

[AnnotationManager#deleteReply](https://sdk.apryse.com/api/web/Core.AnnotationManager.html#event:deleteReply)
{% endtab %}
{% endtabs %}

## Next steps

Now that you know how to add annotations, learn how to [create](/web/annotation/create-annotations.md) them!


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.apryse.com/web/annotation/annotationmanager/replies.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
