PDFium Delphi Component Docs

DetectPageSkew method

Component: TPdf  ·  Unit: PDFium
Measure how far the current page is tilted, as scanned pages usually are.

Syntax

function DetectPageSkew(out Report: TPdfSkewReport): Boolean;

ReportTPdfSkewReport. Receives SkewAngle in degrees (positive means clockwise tilt), Confidence from 0 to 1, the SampleWidth and SampleHeight used for detection, a Succeeded flag, and an ErrorMessage.
ResultBoolean. True when an angle was measured, matching Report.Succeeded.

Description

Detects the skew angle by rendering the page at low resolution and projecting text pixels onto candidate rotation angles; the angle whose projection produces the sharpest line structure wins. Accuracy is about 0.1 degrees

Confidence reflects how much text-line evidence the page offered. A page of running text scores high; a page with a single line or none scores low, and a low score should be treated as "no reliable answer" rather than "no skew"

Detection only measures. To straighten the page, feed the negated angle into a rotation matrix and apply it with TransformPageContent, or render through RenderPageWithMatrix when only the output needs correcting

Example

var Report: TPdfSkewReport;
if Pdf.DetectPageSkew(Report) and (Report.Confidence > 0.5) then
  ShowMessageFmt('Tilted by %.2f degrees', [Report.SkewAngle]);

See Also

TransformPageContent, RenderPageWithMatrix, ApplyOcrSearchLayer, PageRotation