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

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

Reply

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

import 'dart:convert';
import 'dart:io';
import 'nexpdf_ffi.dart';

// annotationsJson: the nexpdf_annotations_json lookup from the Annotations guide
final doc = sdk.open(await File(reviewPath).readAsBytes());
final note = (jsonDecode(takeString(annotationsJson(doc.handle, 0)) ?? '[]') as List).first as Map<String, Object?>;
final noteNum = note['num'] as int, noteGen = note['gen'] as int;

final reply = doc.replyToAnnotation(0, noteNum, noteGen, author: 'Rui', text: 'Agreed, changing the date.');
doc.replyToAnnotation(0, reply, 0, author: 'Ana', text: 'Thanks!');
await File(reviewPath).writeAsBytes(doc.save());

Read a thread

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

for (final r in doc.annotationReplies(0, noteNum, noteGen).cast<Map<String, Object?>>()) {
  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 null for plain replies.

Set a review state

doc.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
doc.setAnnotationState(0, noteNum, noteGen, author: 'Ana', state: 'Accepted');

The three calls throw NexPdfException when the annotation does not exist or the license lacks the module. Threads and states are also part of real-time collaboration: replies sync as comment records.

On this page