Skip to Content
NexPDF

Comment threads

Reply to annotations, read whole comment threads and set review states such as Accepted or Completed, with NexPDF for Android.

English

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 lists them.

Reply

replyToAnnotation(pageIndex, num, gen, author, text) adds a reply and returns the reply's object number (its generation is 0), or 0 on failure with the reason in NexPdfJni.lastError(). Reply to a reply the same way.

import com.nexdevit.nexpdf.NexPdfDocument
import com.nexdevit.nexpdf.NexPdfJni
import org.json.JSONArray

NexPdfDocument.openBytes(review).use { doc ->
    val note = JSONArray(NexPdfJni.annotationsJson(doc.handle(), 0)).getJSONObject(0)
    val num = note.getInt("num")
    val gen = note.getInt("gen")

    val reply = doc.replyToAnnotation(0, num, gen, "Rui", "Agreed, changing the date.")
    check(reply != 0) { NexPdfJni.lastError() }
    doc.replyToAnnotation(0, reply, 0, "Ana", "Thanks!")
    File(filesDir, "review.pdf").writeBytes(doc.saveBytes())
}

Read a thread

annotationRepliesJson(pageIndex, num, gen) returns the thread under an annotation, oldest first, replies to replies included:

val thread = JSONArray(doc.annotationRepliesJson(0, num, gen))
for (i in 0 until thread.length()) {
    val r = thread.getJSONObject(i)
    Log.i("NexPDF", "${r.getString("date")} ${r.getString("author")} ${r.getString("text")} ${r.get("in_reply_to")} ${r.opt("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 null for plain replies.

Set a review state

setAnnotationState(pageIndex, num, gen, author, state) records a reviewer's decision as a hidden state reply and returns its object number, or 0 on failure:

ModelStates
ReviewAccepted, Rejected, Cancelled, Completed, None
MarkedMarked, Unmarked
doc.setAnnotationState(0, num, gen, "Ana", "Accepted")

For raw handles the same calls are NexPdfJni.replyToAnnotation(handle, …), annotationRepliesJson(handle, …) and setAnnotationState(handle, …). Threads and states are also part of real-time collaboration: replies sync as comment records.

On this page