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:
- Retrieve the page object where you want to create the text reply from CPDFDocument.
- Get the annotation on the page object.
- Create a text reply annotation on the annotation and add the reply content.
Here's an example code for creating a text reply:
// 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"
}
// 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:
- Retrieve the page object where you want to create the state reply from
CPDFDocument
. - Get the annotation on the page object.
- Create mark state reply annotations and review state reply annotations on the annotation.
Here's an example code for creating state replies:
// 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)
}
// 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
Name | Description |
---|---|
CPDFAnnotationStateMarked | Check state, used for mark replies |
CPDFAnnotationStateUnMarked | Uncheck state, used for mark replies |
CPDFAnnotationStateAccepted | Accepted state, used for review replies |
CPDFAnnotationStateRejected | Rejected state, used for review replies |
CPDFAnnotationStateCanceled | Canceled state, used for review replies |
CPDFAnnotationStateCompleted | Completed state, used for review replies |
CPDFAnnotationStateNone | No state, used for review replies |
CPDFAnnotationStateError | Error 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:
- Retrieve the page object you need from
CPDFDocument
. - Get the annotation on the page object.
- Get all replies of the annotation and distinguish the reply types.
Here's an example code for getting all replies:
// 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
}
}
}
// 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
Name | Description |
---|---|
CPDFReplyAnnotationTypeNone | Non-reply annotation type, used to distinguish between reply annotations and normal annotations |
CPDFReplyAnnotationTypeReply | Text reply annotation type |
CPDFReplyAnnotationTypeMark | Mark state reply annotation type |
CPDFReplyAnnotationTypeReview | Review state reply annotation type |