PDFium Component Docs

GenerateFormAppearances method

Component: TPdf  ·  Unit: PDFium
Tạo lại /AP (appearance stream) cho mọi widget biểu mẫu trên mọi trang bằng cách render từng trang qua FPDF_FFLDraw. Đây là lời gọi đi kèm được khuyến nghị cho các gán FormField[i] := value — nếu không có nó, giá trị biểu mẫu có thể chỉ hiện khi field được focus và bất kỳ thao tác flatten nào sau đó sẽ âm thầm làm mất giá trị. Hãy gọi sau mọi gán FormField[] và trước SaveAs / FlattenPage / FlattenAllPages

Syntax

procedure GenerateFormAppearances;

Description

GenerateFormAppearances rebuilds the /AP (appearance stream) entry for every AcroForm widget across all pages of the loaded document. It does this by rendering each page through the PDFium form-fill engine (FPDF_FFLDraw), which causes the current field values to be baked into the widget's visual representation stored inside the PDF file.

This call is a mandatory companion to FormField[i] := value assignments. Without it, a form field's value is stored in the PDF's data dictionary but has no corresponding appearance stream. PDF viewers typically show the value only while the field has input focus; other viewers may show nothing at all. More critically, any call to FlattenPage or FlattenAllPages without prior appearance generation will silently produce output that is missing the filled-in values.

The correct workflow when filling and locking a form is: assign all FormField[] values → call GenerateFormAppearances once → optionally call FlattenPage / FlattenAllPages → call SaveAs. If you only need to save the filled form without flattening, GenerateFormAppearances is still recommended to ensure maximum compatibility with third-party PDF viewers.

The procedure operates on the entire document in one call; there is no per-page variant.

Example

begin
  // Assign form field values
  Pdf1.FormField[0] := 'Alice Example';
  Pdf1.FormField[1] := 'alice@example.com';
  Pdf1.FormField[2] := '2026-05-20';
  
  // Bake appearance streams so values are visible in all viewers
  Pdf1.GenerateFormAppearances;
  
  // Flatten and save a non-editable copy
  Pdf1.FlattenAllPages;
  Pdf1.SaveAs('output_filled_flat.pdf');
end;

See Also

FlattenPage, FlattenAllPages, FormField, SaveAs