PDFium Delphi Component Docs

CreateAnnotation 方法

元件: TPdf  ·  單元: PDFium
建立新的註解

語法

procedure CreateAnnotation(const Annotation: TPdfAnnotation);

AnnotationTPdfAnnotation。描述所要建立註解的記錄。主要欄位包含 Subtype(註解類型,例如高亮度、文字註記、筆跡)、Rectangle(PDF 使用者空間座標中的週框)、ContentsText(註解文字)、HasColor、Color 與 ColorAlpha。傳遞記錄前請填入所有相關欄位

說明

CreateAnnotation 會使用 TPdfAnnotation 記錄中提供的屬性,將新的註解新增至目前頁面。該註解會附加至頁面的註解陣列,並可立即透過 Annotation[AnnotationCount - 1] 存取

TPdfAnnotation 記錄會擷取註解類型(Subtype)、其在頁面上的位置(Rectangle,以原點在左下角的 PDF 使用者空間點表示)、可見文字或工具提示(ContentsText),以及顯示顏色(HasColor、Color、ColorAlpha)。呼叫此程序前,請設定與所選子類型相關的每個欄位;未設定的欄位會保留預設值

建立註解後,請呼叫 SaveAs 將變更保存至磁碟。若要移除註解,請使用 DeleteAnnotation 並傳入適當的從 0 起始索引

範例

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;

另請參閱

Annotation, AnnotationCount, DeleteAnnotation