PDFium Component Docs

FlattenPage method

Component: TPdf  ·  Unit: PDFium
Gộp chú thích và widget biểu mẫu trên trang hiện tại thành nội dung trang vĩnh viễn (không thể chỉnh sửa). nFlag chọn hồ sơ gộp: FLAT_NORMALDISPLAY (0) cho hiển thị trên màn hình hoặc FLAT_PRINT (1) cho đầu ra in ấn. Trả về một trong FLATTEN_SUCCESS, FLATTEN_NOTHINGTODO hoặc FLATTEN_FAIL. Hãy gọi GenerateFormAppearances trước khi gộp các giá trị biểu mẫu đã điền

Syntax

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

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

Return Value

Một trong ba hằng số nguyên: FLATTEN_SUCCESS (1) — chú thích đã được gộp thành công vào nội dung trang; FLATTEN_NOTHINGTODO (2) — trang không có chú thích hoặc widget nào để gộp; FLATTEN_FAIL (0) — thao tác thất bại

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