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 Go.

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). Reply to a reply the same way.

doc, err := nexpdf.Open("review.pdf")
if err != nil {
	log.Fatal(err)
}
defer doc.Close()

s, err := doc.AnnotationsJSON(0)
if err != nil {
	log.Fatal(err)
}
var annots []struct {
	Num uint32 `json:"num"`
	Gen uint16 `json:"gen"`
}
json.Unmarshal([]byte(s), &annots)
note := annots[0]

reply, err := doc.ReplyToAnnotation(0, note.Num, note.Gen, "Rui", "Agreed, changing the date.")
if err != nil {
	log.Fatal(err)
}
doc.ReplyToAnnotation(0, uint32(reply), 0, "Ana", "Thanks!")
doc.Save("review.pdf", false)

Read a thread

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

type Reply struct {
	Num       uint32 `json:"num"`
	Gen       uint16 `json:"gen"`
	InReplyTo struct {
		Num uint32 `json:"num"`
		Gen uint16 `json:"gen"`
	} `json:"in_reply_to"`
	Author     string  `json:"author"`
	Date       string  `json:"date"`
	Text       string  `json:"text"`
	State      *string `json:"state"`
	StateModel *string `json:"state_model"`
}

s, err := doc.AnnotationRepliesJSON(0, note.Num, note.Gen)
if err != nil {
	log.Fatal(err)
}
var thread []Reply
json.Unmarshal([]byte(s), &thread)
for _, r := range thread {
	fmt.Println(r.Date, r.Author, r.Text, r.InReplyTo.Num)
}

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:

ModelStates
ReviewAccepted, Rejected, Cancelled, Completed, None
MarkedMarked, Unmarked
if _, err := doc.SetAnnotationState(0, note.Num, note.Gen, "Ana", "Accepted"); err != nil {
	log.Fatal(err)
}

Threads and states are also part of real-time collaboration: replies sync as comment records.

On this page