Comments and replies

Every annotation can carry a discussion thread. You build the thread as a list of Reply objects and assign it to the annotation’s replies property. Each reply has a comment and a User, and each user has a name and a Role (Role.EDITOR or Role.VIEWER).

Add replies to an annotation

The example below creates an area annotation and attaches a two-message conversation between two users before saving the document.

from groupdocs.annotation import Annotator
from groupdocs.annotation.models import Rectangle, Reply, User, Role
from groupdocs.annotation.models.annotation_models import AreaAnnotation
from groupdocs.pydrawing import Color

def add_replies_to_annotation():
    with Annotator("./sample.pdf") as annotator:
        area = AreaAnnotation()
        area.box = Rectangle(100, 100, 100, 100)
        area.background_color = Color.yellow.to_argb()
        area.page_number = 0
        area.message = "Please review this section"

        # Attach a threaded discussion to the annotation
        first_reply = Reply()
        first_reply.comment = "Good catch, I'll take a look."
        first_reply.user = User(name="Tom", role=Role.EDITOR)

        second_reply = Reply()
        second_reply.comment = "Agreed, looks resolved now."
        second_reply.user = User(name="Jack", role=Role.VIEWER)

        area.replies = [first_reply, second_reply]

        annotator.add(area)
        annotator.save("./output.pdf")

if __name__ == "__main__":
    add_replies_to_annotation()

sample.pdf is the sample file used in this example. Click here to download it.

Binary file (PDF, 91 KB)

Download full output