PDFium Component Docs

FlattenAllPages method

Component: TPdf  ·  Unit: PDFium
Hàm bọc tiện dụng để gộp mọi trang trong tài liệu. Trả về True khi mọi trang đều hoàn tất với FLATTEN_SUCCESS hoặc FLATTEN_NOTHINGTODO. Quy trình được khuyến nghị: GenerateFormAppearances → FlattenAllPages → SaveAs

Syntax

function FlattenAllPages(nFlag: Integer = FLAT_NORMALDISPLAY): Boolean;

nFlagInteger. Selects the flattening profile applied to every page. Pass FLAT_NORMALDISPLAY (0, default) to optimize for on-screen viewing, or FLAT_PRINT (1) to optimize for printed output.

Return Value

True if every page in the document returned either FLATTEN_SUCCESS (1) or FLATTEN_NOTHINGTODO (2); False if any page returned FLATTEN_FAIL (0).

Description

FlattenAllPages is a convenience wrapper that iterates over every page in the loaded document and calls the equivalent of FlattenPage on each one. Annotations and AcroForm widgets across all pages are merged into permanent, non-editable page content in a single call.

The method returns True only when all pages complete with FLATTEN_SUCCESS or FLATTEN_NOTHINGTODO. A single page returning FLATTEN_FAIL causes the method to return False, though flattening continues for the remaining pages.

When the document contains filled-in form fields, always call GenerateFormAppearances before FlattenAllPages. Without appearance streams the field values will not appear in the flattened output. The recommended full workflow is: assign FormField[] values → GenerateFormAppearancesFlattenAllPagesSaveAs.

To flatten a single page and inspect its individual result code use FlattenPage instead.

Example

begin
  // Fill fields, generate appearances, flatten entire document
  Pdf1.FormField[0] := 'Jane Doe';
  Pdf1.FormField[1] := '2026-05-20';
  Pdf1.GenerateFormAppearances;
  if Pdf1.FlattenAllPages(FLAT_NORMALDISPLAY) then
    Pdf1.SaveAs('output_flat_all.pdf')
  else
    ShowMessage('One or more pages could not be flattened');
end;

See Also

FlattenPage, GenerateFormAppearances, SaveAs