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), Rectangle (bounding rectangle in PDF user-space coordinates), ContentsText (the annotation text), HasColor, Color, and ColorAlpha. 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 (Rectangle, in PDF user-space points with the origin at the lower-left), the visible text or tooltip (ContentsText), and the display color (HasColor, Color, ColorAlpha). Set every field that is relevant to the chosen subtype before calling this procedure; unset fields are left at their default 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.PageNumber := 1;
Ann := Default(TPdfAnnotation);
Ann.Subtype := anHighlight;
Ann.Rectangle.Left := 72.0;
Ann.Rectangle.Bottom := 680.0;
Ann.Rectangle.Right := 300.0;
Ann.Rectangle.Top := 695.0;
Ann.ContentsText := 'Key figure — review before sign-off';
Ann.HasColor := True;
Ann.Color := clYellow;
Ann.ColorAlpha := 255;
Pdf1.CreateAnnotation(Ann);
Pdf1.SaveAs('output_annotated.pdf');
end;