Skip to content
Lamina PDF
0.9.0
GitHub
Open the web app

Answer a review

You’ll answer the review left on a report: reply to the note asking a question, and mark the highlighted line as done. You need this for a review tool that lists a document’s comments, or a script that closes every comment a checker has handled.

commentThreads gives each comment as a thread: the comment, its replies in order, the status set on it and, for a highlight, the text it marks. The addReply and setReviewState edits answer a comment and set its status. Here they answer the comments left by Mark up a page:

packages/sdk/examples/review-comments.ts
// Answer a review: read the comments on a marked-up report, reply to a question and mark a
// highlight done.
// The comments come back as threads, each with its replies and the status set on it, and a
// highlight's thread carries the text it marks. A reply and a status are annotations of their
// own, so the review keeps its history.
import { Document, type Op } from "@laminapdf/sdk";
/** Who answers the review. */
const ME = "Grace Hopper";
/**
* The document with a reply to every note that asks a question, and every highlight marked
* done, saved incrementally. `at` is when the review was answered, as a PDF date. Needs
* `init({ extract: true })`.
*/
export function reviewComments(bytes: Uint8Array, at: string): Uint8Array<ArrayBuffer> {
using doc = Document.open(bytes);
const ops: Op[] = [];
for (const thread of doc.commentThreads()) {
const { id, subtype, contents } = thread.comment;
if (subtype === "Text" && contents?.endsWith("?")) {
const reply = { parent: id, contents: "June's figures are in the appendix.", author: ME, created: at };
ops.push({ op: "addReply", args: reply });
} else if (subtype === "Highlight" && thread.review !== "Completed") {
// `quoted` is the text the highlight marks, for a list of what was checked.
ops.push({ op: "setReviewState", args: { target: id, state: "completed", author: ME, created: at } });
}
}
// Every answer is one undo step.
doc.apply(ops);
return doc.save({ mode: "incremental" });
}
Page 1 of review_comments.pdf
Open review_comments.pdf (2 pages, 31 KB)

The page looks the same as before: a reply and a status draw nothing on the page. Open the result in a reader with a comments panel, such as Acrobat, and the note has a reply from Grace Hopper, and the highlight is marked Completed.

  • A reply and a status are annotations of their own, each pointing at the comment it answers, as ISO 32000-2 describes and Acrobat writes them. Changing a status adds a new one rather than replacing the old, so the file keeps the review’s history. A thread’s review is its latest Review status, by date.
  • Each reply and status sits over its comment and draws nothing, so no reader shows a second icon on the page. It still prints, which keeps a PDF/A file valid.
  • A thread can hold replies to replies, and a reply on another page than its comment. Each part says which page it is on.
  • quoted is the text under a highlight, underline or strike-out, read from the page. It needs the extract or text module.
  • Some apps leave a reply to a comment that’s gone, or replies that answer each other in a ring. Each comes back as a thread of its own marked broken, so nothing is lost.
  • The author and dates come from your code, never from a clock inside Lamina PDF, so the same edit gives the same file wherever it runs.
  • Another status: "accepted", "rejected", "cancelled", "completed" or "none" set the review status. "marked" and "unmarked" set a reviewer’s check mark, which a thread gives as marked.
  • Some pages only: pass page indexes, doc.commentThreads([0, 1]), for the threads whose comments are on those pages.
  • Delete comments: doc.deleteAnnotations(ids) deletes a selection in one undo step, each comment with its replies, statuses and pop-up. Select a comment and one of its replies, and both go.
  • Edit a reply: updateAnnot changes a reply’s text like any other annotation’s.
  • A signed file: you can answer a review on a certified file that allows comments, or one with only approval signatures. Lamina PDF appends the answers as a new revision, and the signatures stay valid.

Next: add links, another annotation you can add to a page.