PDFium Delphi Component Docs

CompareWith method

Component: TPdf  ·  Unit: PDFium
Compare two active documents and return bounded semantic, geometric, and visual evidence

Syntax

function CompareWith(Other: TPdf; const Options: TPdfDocumentDiffOptions; out Report: TPdfDocumentDiffReport): Boolean;

OtherTPdf. The other active document
OptionsTPdfDocumentDiffOptions. Fields RenderWidth, RenderHeight, ColorTolerance, CompareText, ComparePageGeometry, and MaxPages, with a Default class function
ReportTPdfDocumentDiffReport. Fields Equivalent, Truncated, LeftPageCount, RightPageCount, ComparedPageCount, DifferentPageCount, PixelDifferenceCount, and Differences; each TPdfPageDifference carries PageIndex, TextDifferent, GeometryDifferent, PixelDifferenceCount, and PixelBounds
ResultBoolean. True when the documents are equivalent under the selected options

Description

The comparison uses PDFium text extraction and rendering rather than interpreting content streams in parallel

Geometry includes page dimensions and rotation; visual comparison applies the caller colour tolerance per channel and reports the changed pixel bounds

MaxPages bounds work for untrusted or very large documents, and Truncated reports when the comparison stopped at that limit

The current page of both documents is restored before the method returns

Page alignment and detailed comparisons

Legacy Default settings compare pages by position; enable AlignPages with True to recognise inserted, deleted and exactly moved pages

Alignment combines extracted text, page geometry and a 64-by-64 rendered fingerprint; repeated-page pairing is deterministic, and pages moved and modified together may be classed as modifications

PagePairs and individual differences expose zero-based LeftPageIndex and RightPageIndex, using -1 for an absent page; Kind takes dpkMatched, dpkModified, dpkMoved, dpkInserted or dpkDeleted

TextDiffMode chooses dtmNone, dtmCharacters or dtmWords; TextChanges supplies UTF-16 LeftStart, LeftLength, RightStart and RightLength while keeping surrogate pairs intact

CollectPixelRegions collects connected-tile PixelRegions with exclusive Right and Bottom edges, retaining the legacy combined PixelBounds as well

Detail work is limited by MaxAlignmentCells, MaxTextCharacters, MaxTextDiffCells, MaxTextTokens, PixelRegionTileSize, MaxPixelRegions and MaxDetailItems; DetailTruncated flags incomplete detail independently of the page-limit Truncated

Report supplies InsertedPageCount, DeletedPageCount and MovedPageCount; individual differences have their own DetailTruncated flag too

RenderDiffOverlay exports a visual overlay owned by the caller; the limited helper algorithms are exposed through FPdfDiff

See Also

RenderPage, Text, ImportImposed