PDFiumVCL Docs

SetFormFieldFlags method

Deze API-entry behoudt identifiers, signatures, codeblokken en PDF-termen in hun oorspronkelijke vorm.
Component: TPdf  ·  Unit: PDFium
Sets AcroForm field flags for the form field at the specified annotation index on the current page.

Syntax

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

IndexInteger. The 0-based annotation index of the form field on the current page. Must be in the range 0 to AnnotationCount - 1.
FlagsTPdfFormFieldFlags. A set of TPdfFormFieldFlag values to apply to the field. These correspond to the AcroForm field flags defined in the PDF specification, such as read-only, required, or no-export.

Description

SetFormFieldFlags writes AcroForm field flags to the form widget annotation at the given 0-based annotation index on the current page. The flags control interactive behaviour of the field: for example, marking it read-only prevents the user from changing its value, while marking it required signals that it must be filled before the form can be submitted.

The Index parameter refers to the annotation index as reported by AnnotationCount, not the form-field index reported by FormFieldCount. Use FormFieldInfo or HasFormFieldAt to identify which annotation indexes correspond to form widgets. To address a field by page coordinates rather than index, use SetFormFieldFlagsAt.

Flag changes take effect immediately in the in-memory document but are not persisted until SaveAs is called. When programmatically locking a form after filling it, the recommended sequence is: assign FormField[] values, call GenerateFormAppearances, set flags to read-only, then call 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