Comment threads
Reply to annotations, read whole comment threads and set review states such as Accepted or Completed, with NexPDF for iOS (Swift).
License module
Replies and review states need the annotations module (Indie tier and above).
A comment thread is an annotation (a note, a highlight, any markup) with the replies people wrote
under it. Replies are annotations too, so Acrobat and other viewers show the same thread. An
annotation is named by its object number and generation (num, gen), as
annotationsJson(pageIndex:) lists them.
Reply
replyToAnnotation(pageIndex:num:generation:author:text:) adds a reply and returns the reply's
object number (its generation is 0). Reply to a reply the same way.
import NexPdf
let doc = try NexPdfDocument.open(url: reviewURL)
let notes = NexPdf.json(try doc.annotationsJson(pageIndex: 0)) as? [[String: Any]] ?? []
guard let note = notes.first else { return }
let num = UInt32(note["num"] as? Int ?? 0)
let gen = UInt16(note["gen"] as? Int ?? 0)
let reply = try doc.replyToAnnotation(pageIndex: 0, num: num, generation: gen, author: "Rui",
text: "Agreed, changing the date.")
try doc.replyToAnnotation(pageIndex: 0, num: UInt32(reply), generation: 0, author: "Ana", text: "Thanks!")
try doc.write(to: reviewURL)Read a thread
annotationRepliesJson(pageIndex:num:generation:) returns the thread under an annotation, oldest
first, replies to replies included:
let thread = NexPdf.json(try doc.annotationRepliesJson(pageIndex: 0, num: num, generation: gen)) as? [[String: Any]] ?? []
for r in thread {
print(r["date"] ?? "", r["author"] ?? "", r["text"] ?? "", r["in_reply_to"] ?? "", r["state"] ?? "")
}Each entry has num, gen, in_reply_to ({"num", "gen"}), author, date (ISO 8601), text,
state and state_model. state and state_model are NSNull for plain replies.
Set a review state
setAnnotationState(pageIndex:num:generation:author:state:) records a reviewer's decision as a
hidden state reply and returns its object number:
| Model | States |
|---|---|
| Review | Accepted, Rejected, Cancelled, Completed, None |
| Marked | Marked, Unmarked |
try doc.setAnnotationState(pageIndex: 0, num: num, generation: gen, author: "Ana", state: "Accepted")Threads and states are also part of real-time collaboration:
replies sync as comment records.