PDFium Delphi Component 文件

SetFormFieldFlags 方法

元件: TPdf  ·  單元: PDFium
為目前頁面上指定註解索引的表單欄位設定 AcroForm 欄位旗標

Syntax

procedure SetFormFieldFlags(Index: Integer; const Flags: TPdfFormFieldFlags);

IndexInteger。表單欄位在目前頁面上以 0 為基底的註解索引。必須在 0 到 AnnotationCount - 1 的範圍內
FlagsTPdfFormFieldFlags。要套用到欄位的 TPdfFormFieldFlag 值集合。這些旗標對應 PDF 規範定義的 AcroForm 欄位旗標,例如唯讀、必填或不可匯出

Description

SetFormFieldFlags 會將 AcroForm 欄位旗標寫入目前頁面上指定之 0 基底註解索引處的表單 widget 註解。旗標控制欄位的互動行為:例如標記為唯讀可防止使用者變更其值,標記為必填則表示送出表單前必須先填寫

Index 參數指的是 AnnotationCount 回報的註解索引,而非 FormFieldCount 回報的表單欄位索引。使用 FormFieldInfo 或 HasFormFieldAt 可找出哪些註解索引對應表單 widget。若要改以頁面座標而非索引指定欄位,請使用 SetFormFieldFlagsAt

旗標變更會立即在記憶體內部文件中生效,但要呼叫 SaveAs 之後才會儲存。以程式方式在填表後鎖定表單時,建議順序為:指派 FormField[] 值、呼叫 GenerateFormAppearances、將旗標設為唯讀,再呼叫 SaveAs

Example

var
  I: Integer;
begin
  Pdf1.PageIndex := 0;
  // Mark every form field on the page as read-only
  for I := 0 to Pdf1.AnnotationCount - 1 do
    if Pdf1.FormFieldInfo[I].FieldType <> fftUnknown then
      Pdf1.SetFormFieldFlags(I, [ffReadOnly]);
  Pdf1.SaveAs('output_readonly.pdf');
end;

See Also

FormField, FormFieldCount, FormFieldInfo, SetFormFieldFlagsAt, HasFormFieldAt