PDFium Delphi Component Docs

FlattenPageRotation method

Component: TPdf  ·  Unit: PDFium
Bakes the current /Rotate of every page into the content stream, page boxes, and annotation rectangles, then resets /Rotate to 0 so the visual layout is preserved without relying on the rotation display hint

Syntax

function FlattenPageRotation(
  const Options : TPdfFlattenRotationOptions;
  out Report : TPdfFlattenRotationReport): Boolean; overload;

function FlattenPageRotation(
  const PageNumbers : array of Integer;
  const Options : TPdfFlattenRotationOptions;
  out Report : TPdfFlattenRotationReport): Boolean; overload;

Description

Many downstream tools (older print pipelines, image extractors, OCR preprocessors, raster converters) ignore the /Rotate page entry and render rotated pages in the wrong orientation. FlattenPageRotation applies the inverse of the current rotation to the page content, annotation rectangles, and page boxes, then sets /Rotate to 0. After the call the visible page is identical to the rotated original, but no longer relies on the viewer applying the rotation hint.

The single-argument overload processes every page; the PageNumbers overload accepts a zero-based array so callers can flatten a subset. Pages already at /Rotate=0 are counted in Report.SkippedPageCount and left untouched.

Internally each rotated page runs through FPDFPage_CountObjects + FPDFPage_GetObject + FPDFPageObj_TransformF for the content, then FPDFPage_GetAnnot + FPDFAnnot_GetRect / FPDFAnnot_SetRect for annotations, then FPDFPage_SetMediaBox / FPDFPage_SetCropBox for the page boxes, and finally FPDFPage_SetRotation with 0. The matrix is derived from the unrotated MediaBox returned by FPDFPage_GetMediaBox.

Parameters

Remarks

Example

var
  Options: TPdfFlattenRotationOptions;
  Report: TPdfFlattenRotationReport;
begin
  Pdf1.FileName := 'C:\Scanned.pdf';
  Pdf1.Active := True;
  Options := TPdfFlattenRotationOptions.Default;
  Pdf1.FlattenPageRotation(Options, Report);
  Pdf1.SaveAs('C:\Scanned_flat.pdf');
end;

See Also

PageRotation, TransformPageObject, SetPageBox