Skip to content
Guides

Annotation Replies

Annotation replies enable you and other users to engage in written discussions directly within the document. ComPDFKit provides convenient APIs for accessing replies in the document, as well as user interface (UI) components for viewing and editing replies.

Creating Text Replies

Text replies allow you to add written responses below annotations, commonly used for discussions related to the annotation.

The steps to create a text reply are as follows:

  1. Retrieve the page object where you want to create the text reply from CPDFDocument.
  2. Get the annotation on the page object.
  3. Create a text reply annotation on the annotation and add the reply content.

Here's an example code for creating a text reply:

swift
// Retrieve the page object where you want to create the note
if let page = document?.page(at: 0) {
  // Get the annotation on the page
  let annotation = page.annotations[0]
  
  // Create a reply annotation and add reply content
  let reply = annotation?.createReply()
  reply?.contents = "ComPDFKit"
}
objective-c
// Retrieve the page object where you want to create the note
CPDFPage *page = [document pageAtIndex:0];

// Get the annotation on the page
CPDFAnnotation *annotation = page.annotations[0];

// Create a reply annotation and add reply content
CPDFAnnotation *reply = [annotation createReplyAnnotation];
reply.contents = @"ComPDFKit";

Creating State Replies

State replies allow you to mark the state of annotations, categorized into mark states and review states, which can be distinguished using the CPDFAnnotationState enumeration type.

The steps to create a state reply are as follows:

  1. Retrieve the page object where you want to create the state reply from CPDFDocument.
  2. Get the annotation on the page object.
  3. Create mark state reply annotations and review state reply annotations on the annotation.

Here's an example code for creating state replies:

swift
// Retrieve the page object where you want to create the note
if let page = document?.page(at: 0) {
  // Get the annotation on the page
  let annotation = page.annotations[0]
  
  // Create a mark state reply
  let checkReply = annotation?.createReplyStateAnnotation(.marked)
  // Create a review state reply
  let reviewReply = annotation?.createReplyStateAnnotation(.rejected)
}
objective-c
// Retrieve the page object where you want to create the note
CPDFPage *page = [document pageAtIndex:0];

// Get the annotation on the page
CPDFAnnotation *annotation = page.annotations[0];

// Create a mark state reply
CPDFAnnotation *checkReply = [annotation createReplyStateAnnotation:CPDFAnnotationStateMarked];
// Create a review state reply
CPDFAnnotation *reviewReply = [annotation createReplyStateAnnotation:CPDFAnnotationStateRejected];

Enumeration Types for State Reply Annotations

NameDescription
CPDFAnnotationStateMarkedCheck state, used for mark replies
CPDFAnnotationStateUnMarkedUncheck state, used for mark replies
CPDFAnnotationStateAcceptedAccepted state, used for review replies
CPDFAnnotationStateRejectedRejected state, used for review replies
CPDFAnnotationStateCanceledCanceled state, used for review replies
CPDFAnnotationStateCompletedCompleted state, used for review replies
CPDFAnnotationStateNoneNo state, used for review replies
CPDFAnnotationStateErrorError state

Getting All Replies

The feature to get all replies allows you to retrieve all replies under an annotation, including text replies and state replies. The CPDFReplyAnnotationType enumeration type can be used to distinguish the reply types.

The steps to get all replies are as follows:

  1. Retrieve the page object you need from CPDFDocument.
  2. Get the annotation on the page object.
  3. Get all replies of the annotation and distinguish the reply types.

Here's an example code for getting all replies:

swift
// Retrieve the page object where you want to get the replies
if let page = document?.page(at: 0) {
  // Get the annotation on the page
  let annotation = page.annotations[0]
  
  // Get all replies of the annotation
  let replies = annotation.replyAnnotations ?? []
  for reply in replies {
      if reply.replyAnnotationType == .reply {
          // Text reply annotation type
      } else if reply.replyAnnotationType == .mark {
          // Mark state reply annotation type
      } else if reply.replyAnnotationType == .review {
          // Review state reply annotation type
      }
  }
}
objective-c
// Retrieve the page object where you want to get the replies
CPDFPage *page = [document pageAtIndex:0];

// Get the annotation on the page
CPDFAnnotation *annotation = page.annotations[0];

// Get all replies of the annotation
NSArray<CPDFAnnotation *> *replies = [annotation replyAnnotations];
for (CPDFAnnotation *reply in replies) {
    if (reply.replyAnnotationType == CPDFReplyAnnotationTypeReply) {
        // Text reply annotation type
    } else if (reply.replyAnnotationType == CPDFReplyAnnotationTypeMark) {
        // Mark state reply annotation type
    } else if (reply.replyAnnotationType == CPDFReplyAnnotationTypeReview) {
        // Review state reply annotation type
    }
}

Enumeration Types for Reply Annotations

NameDescription
CPDFReplyAnnotationTypeNoneNon-reply annotation type, used to distinguish between reply annotations and normal annotations
CPDFReplyAnnotationTypeReplyText reply annotation type
CPDFReplyAnnotationTypeMarkMark state reply annotation type
CPDFReplyAnnotationTypeReviewReview state reply annotation type