InsertAnnotation

Annotations and hotspot links

Description

Inserts an already-built annotation dictionary at a 1-based position in the selected page's /Annots array, shifting the annotations that follow it down. AnnotObjectNumber is the object number of an annotation dictionary produced through the low-level structure API; the function returns 1 on success, or 0 when no document is selected or the object number is not positive.

Syntax

Delphi

Function TPDFlib.InsertAnnotation(Index, AnnotObjectNumber: Integer): Integer;

Parameters

Index is the 1-based position in the selected page's /Annots array where the annotation is placed; a value below 1 is treated as the first position and a value past the current count appends at the end. AnnotObjectNumber is the object number of the annotation dictionary to reference and must be positive; a generation number of 0 is assumed, as it is for every annotation the library itself writes.

Return values

1 when the reference was inserted, creating the page's /Annots array if the page had none. 0 when no document is open, when AnnotObjectNumber is not positive, or when there is no selected page and therefore no page dictionary to attach the array to.

Remarks

The object number is wrapped in an indirect reference without being resolved, so nothing checks that it names an existing object, that the object is a dictionary, or that it carries /Subtype, /Rect and /P: the caller builds the annotation through the low-level structure API and owns the consequences of a bad number, which produce a page that references a missing object rather than an error here. Only an /Annots entry stored on the page dictionary itself is considered, so an array inherited from an ancestor page-tree node is not extended - a new local array is created instead, and the inherited annotations are hidden by it because a local entry overrides the inherited one. The insertion position is honoured rather than appended, which matters because many viewers follow array order for tab navigation and for annotation stacking, and the library drops any cached annotation list so later enumeration sees the new member. No PDF version is raised, and the document has to be saved for the change to persist.