DeskewPage

Image processing, page manipulation, OCR

Description

Detects the correction angle for a scanned page and wraps its existing content in a centred rotation matrix without rasterising or resampling the page

Syntax

Delphi

Function TPDFlib.DeskewPage(Page: Integer; DPI: Double= 0;
  MaxAngle: Double= 0; AngleStep: Double= 0;
  MinConfidence: Double= 0; Options: Integer= 0): Double;

ActiveX

Function PDFlib::DeskewPage(Page As Long, DPI As Double,
  MaxAngle As Double, AngleStep As Double, MinConfidence As Double,
  Options As Long) As Double

DLL

double DLDeskewPage(int InstanceID, int Page, double DPI,
  double MaxAngle, double AngleStep, double MinConfidence,
  int Options);

Parameters

PageThe one-based page number
DPI, MaxAngle, AngleStepThe analysis controls described by AnalyzePageSkewJSON
MinConfidenceThe minimum peak-to-baseline score ratio; zero selects 3
OptionsZero preserves scale and may expose white corners; PDF_DESKEW_FILL_PAGE scales the rotated content enough to fill the unchanged page box

Return values

Returns the correction angle that was applied

Returns zero when the page is already aligned, confidence is below the threshold, the page has insufficient foreground structure, or the operation fails; inspect LastErrorCode to distinguish a valid no-op from an error

Remarks

The analysis bitmap is temporary and bounded, while the saved PDF retains original vector graphics, scan image data, and any existing OCR text layer

All page content layers are enclosed in one outer graphics state so state transitions across a /Contents array keep their original order

The page dimensions and selected page are preserved

Annotations and form widget geometry are not page content and are not transformed, so deskew scanned pages before adding OCR annotations, links, or form fields

LastErrorCode is 116 for invalid parameters and 520 for rendering, analysis, or content transformation failures

See also

AnalyzePageSkewJSON, DeskewPageRange, OCRPage