procedure CreateAnnotation(const Annotation: TPdfAnnotation);
| Annotation | TPdfAnnotation. A record describing the annotation to create. Key fields include SubType (annotation type, e.g. highlight, text note, ink), Rect (bounding rectangle in PDF user-space coordinates), Contents (the annotation text), and Color (the annotation colour). Fill all relevant fields before passing the record. |
CreateAnnotation adds a new annotation to the current page using the properties supplied in the TPdfAnnotation record. The annotation is appended to the page's annotation array and becomes immediately accessible via Annotation[AnnotationCount - 1].
The TPdfAnnotation record captures the annotation type (SubType), its position on the page (Rect, in PDF user-space points with the origin at the lower-left), the visible text or tooltip (Contents), and the display colour (Color). Set every field that is relevant to the chosen subtype before calling this procedure; unset fields are left at their zero values.
After creating annotations, call SaveAs to persist the changes to disk. To remove an annotation use DeleteAnnotation with the appropriate 0-based index.
var
Ann: TPdfAnnotation;
begin
Pdf1.PageIndex := 0;
FillChar(Ann, SizeOf(Ann), 0);
Ann.SubType := asHighlight;
Ann.Rect.Left := 72.0;
Ann.Rect.Bottom := 680.0;
Ann.Rect.Right := 300.0;
Ann.Rect.Top := 695.0;
Ann.Contents := 'Key figure — review before sign-off';
Ann.Colour := clYellow;
Pdf1.CreateAnnotation(Ann);
Pdf1.SaveAs('output_annotated.pdf');
end;