Annotation Replies
ComPDF React Native SDK provides annotation reply APIs for adding, reading, updating, and removing replies on PDF annotations. You can also set mark states and review states on annotations or annotation replies. These APIs are useful for document review, collaborative annotation workflows, feedback tracking, and approval flows.
API Overview
Annotation reply APIs are available on CPDFDocument:
addAnnotationReply(
annotation: CPDFAnnotation,
options: { content: string; title?: string }
): Promise<CPDFReplyAnnotation | null>;
getAnnotationReplies(
annotation: CPDFAnnotation
): Promise<CPDFReplyAnnotation[]>;
updateAnnotationReply(
reply: CPDFReplyAnnotation,
options: { content: string; title?: string }
): Promise<boolean>;
removeAnnotationReply(reply: CPDFReplyAnnotation): Promise<boolean>;
removeAllAnnotationReplies(annotation: CPDFAnnotation): Promise<boolean>;
setAnnotationMarkState(
annotation: CPDFAnnotation,
state: CPDFAnnotationMarkState
): Promise<boolean>;
getAnnotationMarkState(
annotation: CPDFAnnotation
): Promise<CPDFAnnotationMarkState>;
setAnnotationReviewState(
annotation: CPDFAnnotation,
state: CPDFAnnotationReviewState
): Promise<boolean>;
getAnnotationReviewState(
annotation: CPDFAnnotation
): Promise<CPDFAnnotationReviewState>;API description:
| API | Description |
|---|---|
addAnnotationReply | Adds a plain reply to an annotation |
getAnnotationReplies | Gets all plain replies attached to an annotation |
updateAnnotationReply | Updates the content and optional title of a plain reply |
removeAnnotationReply | Removes one plain reply |
removeAllAnnotationReplies | Removes all plain replies attached to an annotation |
setAnnotationMarkState | Sets the mark state of an annotation or reply |
getAnnotationMarkState | Gets the mark state of an annotation or reply |
setAnnotationReviewState | Sets the review state of an annotation or reply |
getAnnotationReviewState | Gets the review state of an annotation or reply |
Reply Model
Annotation replies are represented by CPDFReplyAnnotation.
class CPDFReplyAnnotation extends CPDFAnnotation {
modifyDate: Date | null;
}Because CPDFReplyAnnotation extends CPDFAnnotation, it includes common annotation fields used in review workflows:
| Property | Description |
|---|---|
page | Zero-based page index |
title | Reply author or title |
content | Reply content |
createDate | Reply creation time, if provided by the native SDK |
modifyDate | Reply modification time, if provided by the native SDK |
markState | Current mark state |
reviewState | Current review state |
When updating, removing, or setting the state of a reply, use a CPDFReplyAnnotation object returned by addAnnotationReply or getAnnotationReplies. Do not manually construct a CPDFReplyAnnotation and pass it to these APIs.
Mark States and Review States
Mark states:
enum CPDFAnnotationMarkState {
MARKED = "marked",
UNMARKED = "unmarked",
}Review states:
enum CPDFAnnotationReviewState {
ACCEPTED = "accepted",
REJECTED = "rejected",
CANCELLED = "cancelled",
COMPLETED = "completed",
NONE = "none",
ERROR = "error",
}Mark states and review states can be set on the parent annotation or on a reply annotation:
await document.setAnnotationMarkState(
annotation,
CPDFAnnotationMarkState.MARKED
);
await document.setAnnotationReviewState(
annotation,
CPDFAnnotationReviewState.ACCEPTED
);Get an Annotation Object
Most reply operations start from an existing annotation. The following example gets the first annotation on page 1.
const page = document.pageAtIndex(0);
const annotations = await page.getAnnotations();
if (!annotations.length) {
return;
}
const annotation = annotations[0];Page indexes are zero-based.
Add a Reply
Use addAnnotationReply to add a plain reply to an annotation.
const reply = await document.addAnnotationReply(annotation, {
content: "Please review this highlight.",
title: "Alex",
});
if (!reply) {
throw new Error("Add annotation reply failed.");
}
console.log("Reply content:", reply.content);content is required. title is optional and is commonly used as the reply author name.
Read Replies
Use getAnnotationReplies to get all plain replies attached to an annotation.
const replies = await document.getAnnotationReplies(annotation);
for (const reply of replies) {
console.log("Author:", reply.title);
console.log("Content:", reply.content);
console.log("Mark state:", reply.markState);
console.log("Review state:", reply.reviewState);
}The returned list contains plain replies only. Internal state replies used to store mark and review states are not exposed as separate reply items.
Update a Reply
Use updateAnnotationReply to update the content and optional title of an existing reply.
const replies = await document.getAnnotationReplies(annotation);
if (replies.length) {
const success = await document.updateAnnotationReply(replies[0], {
content: "Updated reply content.",
title: "Alex",
});
if (!success) {
throw new Error("Update annotation reply failed.");
}
}The reply parameter should come from getAnnotationReplies or addAnnotationReply.
Remove One Reply
Use removeAnnotationReply to remove one plain reply.
const replies = await document.getAnnotationReplies(annotation);
if (replies.length) {
const success = await document.removeAnnotationReply(replies[0]);
if (!success) {
throw new Error("Remove annotation reply failed.");
}
}Remove All Replies
Use removeAllAnnotationReplies to remove all plain replies attached to an annotation.
const success = await document.removeAllAnnotationReplies(annotation);
if (!success) {
throw new Error("Remove all annotation replies failed.");
}This API removes plain replies only. Mark state and review state information is preserved.
Set Mark and Review States on a Reply
You can set the mark state or review state of a reply.
const replies = await document.getAnnotationReplies(annotation);
if (replies.length) {
const reply = replies[0];
await document.setAnnotationMarkState(
reply,
CPDFAnnotationMarkState.MARKED
);
await document.setAnnotationReviewState(
reply,
CPDFAnnotationReviewState.COMPLETED
);
}After setting a reply state, call getAnnotationReplies again if the UI needs the latest reply data.
Set States on the Parent Annotation
You can also set mark and review states directly on the parent annotation.
await document.setAnnotationMarkState(
annotation,
CPDFAnnotationMarkState.MARKED
);
await document.setAnnotationReviewState(
annotation,
CPDFAnnotationReviewState.ACCEPTED
);
const markState = await document.getAnnotationMarkState(annotation);
const reviewState = await document.getAnnotationReviewState(annotation);
console.log("Mark:", markState);
console.log("Review:", reviewState);Use in CPDFReaderView
In a reader screen, call the same APIs through pdfReaderRef.current?._pdfDocument.
import {
CPDFReaderView,
CPDFAnnotationReviewState,
} from "@compdfkit_pdf_sdk/react_native";
async function addReplyToFirstAnnotation(reader: CPDFReaderView) {
const document = reader._pdfDocument;
const pageIndex = await reader.getCurrentPageIndex();
const annotations = await document.pageAtIndex(pageIndex).getAnnotations();
if (!annotations.length) {
return;
}
const reply = await document.addAnnotationReply(annotations[0], {
content: "Reviewed in the reader.",
title: "Reviewer",
});
if (reply) {
await document.setAnnotationReviewState(
reply,
CPDFAnnotationReviewState.COMPLETED
);
}
}This approach is suitable for custom review panels, annotation lists, and collaboration toolbars.
Complete Example
The following example gets the first annotation on page 1 in a reader, adds a reply, sets the review state on that reply, and reads the reply list again.
import {
CPDFReaderView,
CPDFAnnotation,
CPDFReplyAnnotation,
CPDFAnnotationReviewState,
} from "@compdfkit_pdf_sdk/react_native";
async function reviewFirstAnnotation(reader: CPDFReaderView) {
const document = reader._pdfDocument;
const page = document.pageAtIndex(0);
const annotations: CPDFAnnotation[] = await page.getAnnotations();
if (!annotations.length) {
return;
}
const annotation = annotations[0];
const reply: CPDFReplyAnnotation | null =
await document.addAnnotationReply(annotation, {
content: "Please verify this annotation.",
title: "Reviewer",
});
if (!reply) {
throw new Error("Add annotation reply failed.");
}
await document.setAnnotationReviewState(
reply,
CPDFAnnotationReviewState.COMPLETED
);
const replies = await document.getAnnotationReplies(annotation);
console.log("Reply count:", replies.length);
}Notes
- When updating or removing a reply, use the
CPDFReplyAnnotationobject returned by the SDK. - Do not rely on internal annotation identifiers in application logic. Pass SDK-returned annotation or reply objects directly when operating on annotations or replies.
getAnnotationRepliesreturns plain replies only. State replies are handled internally by the SDK.removeAllAnnotationRepliesremoves plain replies and preserves mark state and review state information.- After setting mark or review states, read the annotation or replies again if the UI needs the latest model data.
- Annotation and reply APIs use zero-based page indexes.
- To persist changes to the PDF file, save the document after completing the operations.