Skip to content

Expose the annotation name (/NM) and the subject (/Subj) - #21663

Open
gronke wants to merge 1 commit into
mozilla:masterfrom
gronke:expose-annotation-name-and-subject
Open

Expose the annotation name (/NM) and the subject (/Subj)#21663
gronke wants to merge 1 commit into
mozilla:masterfrom
gronke:expose-annotation-name-and-subject

Conversation

@gronke

@gronke gronke commented Jul 30, 2026

Copy link
Copy Markdown

Two entries that are in every annotated PDF and reach no caller.

/NM - the annotation name

(Optional; PDF 1.4) The annotation name, a text string uniquely identifying it among all the annotations on its page.
— ISO 32000-1, Table 164

This is not data.id. data.id is the object reference ("819R"), which changes when a file is rewritten and says nothing about what the document calls the annotation.
/NM is the name the document itself gives it, and the name viewers key their own records off - Acrobat writes one on everything it creates.

Anything correlating a PDF's annotations with state held outside the file needs it.
Without it a caller has to join on the object id, which breaks the moment the file is written again.

Read on Annotation, where the common annotation dictionary is parsed, as data.annotationName.

/Subj - what the annotation is about

(Optional; PDF 1.5) Text representing a short description of the subject being addressed by the annotation.
— ISO 32000-1, Table 170

A markup-annotation entry, so it is read in MarkupAnnotation as data.subjectObj, in the same { str, dir } shape as titleObj and contentsObj - it is a text string and can be right-to-left.
A group member inherits it from the primary annotation, alongside the title, contents and dates it already inherits.

Notes

Both are read-only additions to the data object. Nothing that consumes it changes, and no display behaviour changes - subjectObj is deliberately not wired into the popup, which would be a separate decision.

Four unit tests: each field present and absent, plus the group-inheritance test extended to assert the inherited subject.

See https://opensource.adobe.com/dc-acrobat-sdk-docs/pdfstandards/PDF32000_2008.pdf

Both are in the file and neither reaches `getAnnotations()`, so a caller that reads a PDF's own annotations cannot see what the document calls them or what they say they are about.

`/NM` is the annotation name: "a text string uniquely identifying it among all the annotations on its page" (ISO 32000-1, Table 164).
It is not `data.id`, which is the object reference — a caller correlating annotations with anything outside the file needs the name the document gives them, and that is also the name viewers key their own records off.
It is read on `Annotation`, where the common dictionary lives, as `data.annotationName`.

`/Subj` is "text representing a short description of the subject being addressed by the annotation" (Table 170), a markup-annotation entry.
It is read as `data.subjectObj` in the same `{ str, dir }` shape as `titleObj` and `contentsObj`, since it is a text string and can be right-to-left.
A group member inherits it from the primary annotation, alongside the title, the contents and the dates it already inherits.

Both are read-only additions to the data object; nothing that consumes it changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants