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

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

Reply

reply_to_annotation(page_index, num, generation, author, text) adds a reply and returns the reply's object number as an i32 (its generation is 0). Reply to a reply the same way.

use nexpdf_sdk::Document;

fn main() -> nexpdf_sdk::Result<()> {
    let mut doc = Document::open("review.pdf")?;
    let list = doc.annotations_json_value(0)?;              // `serde` feature
    let note = &list[0];
    let num = note["num"].as_u64().unwrap_or(0) as u32;
    let generation = note["gen"].as_u64().unwrap_or(0) as u16;

    let reply = doc.reply_to_annotation(0, num, generation, "Rui", "Agreed, changing the date.")?;
    doc.reply_to_annotation(0, reply as u32, 0, "Ana", "Thanks!")?;
    doc.save("review.pdf")
}

Read a thread

annotation_replies_json(page_index, num, generation) returns the thread under an annotation, oldest first, replies to replies included:

for r in doc.annotation_replies_json_value(0, num, generation)?.as_array().into_iter().flatten() {
    println!("{} {} {} {} {}", 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 null for plain replies.

Set a review state

set_annotation_state(page_index, num, generation, 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
doc.set_annotation_state(0, num, generation, "Ana", "Accepted")?;

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

On this page