procedure CreateAnnotation(const Annotation: TPdfAnnotation);
| Annotation | TPdfAnnotation。描述要创建的注释的记录。关键字段包括 Subtype(注释类型,例如高亮、文本备注、墨迹)、Rectangle(PDF 用户空间坐标中的边界矩形)、ContentsText(注释文本)、HasColor、Color 和 ColorAlpha。传递记录前请填写所有相关字段 |
CreateAnnotation 使用 TPdfAnnotation 记录中提供的属性向当前页面添加新注释。注释被追加到页面的注释数组中,并可通过 Annotation[AnnotationCount - 1] 立即访问
TPdfAnnotation 记录捕获注释类型(Subtype)、其在页面上的位置(Rectangle,采用 PDF 用户空间点,原点位于左下角)、可见文本或工具提示(ContentsText)以及显示颜色(HasColor、Color、ColorAlpha)。调用此过程前,请设置与所选子类型相关的每个字段;未设置的字段保留其默认值
创建注释后,调用 SaveAs 将更改持久化到磁盘。要删除注释,请使用带有相应从零开始索引的 DeleteAnnotation
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;