PDFiumVCL Docs

FlattenPage method

이 API 항목은 식별자, 시그니처, 코드 블록, PDF 용어를 원래 형태로 유지합니다.
Component: TPdf  ·  Unit: PDFium
Flattens annotations and form widgets on the current page into permanent (non-editable) page content. nFlag selects the flattening profile: FLAT_NORMALDISPLAY (0) for screen display or FLAT_PRINT (1) for printed output. Returns one of FLATTEN_SUCCESS, FLATTEN_NOTHINGTODO, or FLATTEN_FAIL. Call GenerateFormAppearances first when flattening filled-in form values.

Syntax

function FlattenPage(nFlag: Integer = FLAT_NORMALDISPLAY): Integer;

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

Return Value

One of three integer constants: FLATTEN_SUCCESS (1) — annotations were merged into the page content successfully; FLATTEN_NOTHINGTODO (2) — the page had no annotations or widgets to flatten; FLATTEN_FAIL (0) — the operation failed.

Description

FlattenPage merges all annotations and AcroForm widgets on the current page into the permanent, non-editable page content stream. Once flattened, the annotations are no longer interactive — they become ordinary graphics that cannot be edited, deleted, or submitted. This is the standard technique for producing a "locked" PDF that preserves the visual appearance of a filled form or annotated document.

The nFlag parameter selects the rendering profile used when drawing widgets into the page content. Use FLAT_NORMALDISPLAY (0) for documents that will be viewed on screen, and FLAT_PRINT (1) for documents destined for printing.

When the page contains filled-in form fields, you must call GenerateFormAppearances before FlattenPage. Without appearance streams, the flattener has no visual representation to merge and will silently omit the field values from the output. The recommended sequence for a single page is: assign FormField[] values → GenerateFormAppearancesFlattenPageSaveAs.

To flatten every page in a document in one call use FlattenAllPages. Check the return value against FLATTEN_FAIL to detect errors; FLATTEN_NOTHINGTODO is not an error condition.

Example

var
  Res: Integer;
begin
  Pdf1.PageIndex := 0;
  // Fill a form field, regenerate appearances, then flatten
  Pdf1.FormField[0] := 'John Smith';
  Pdf1.GenerateFormAppearances;
  Res := Pdf1.FlattenPage(FLAT_NORMALDISPLAY);
  if Res = FLATTEN_FAIL then
    ShowMessage('Flatten failed')
  else
    Pdf1.SaveAs('output_flat.pdf');
end;

See Also

FlattenAllPages, GenerateFormAppearances, SaveAs, Annotation