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, MaxPages, AlignPages, TextDiffMode, CollectPixelRegions, MaxAlignmentCells, MaxTextCharacters, MaxTextDiffCells, MaxTextTokens, PixelRegionTileSize, MaxPixelRegions, MaxDetailItems, and SimilarityOptions, with a Default class function
ReportTPdfDocumentDiffReport. Fields Equivalent, Truncated, LeftPageCount, RightPageCount, ComparedPageCount, DifferentPageCount, PixelDifferenceCount, Differences, PagePairs, InsertedPageCount, DeletedPageCount, MovedPageCount, and DetailTruncated; each TPdfPageDifference carries PageIndex, LeftPageIndex, RightPageIndex, Kind, TextDifferent, GeometryDifferent, PixelDifferenceCount, PixelBounds, TextChanges, PixelRegions, and DetailTruncated
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 exact-page pairing is deterministic

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

SimilarityOptions is a TPdfDiffAlignmentOptions record initialised by Default; with AlignPages enabled, set SimilarityOptions.MatchSimilarPages to True to identify confident text-similar pages that moved and changed together

Matching requires equal page geometry and unique mutual candidates; PagePairs[].Similarity reports a 0..1000 evidence score and SimilarityAmbiguous exposes unresolved candidates before positional gap fallback

dpkMovedModified increments MovedPageCount and retains text and pixel details; the overlay uses the move colour for both kinds of movement; blank, image-only, short and low-information pages fall outside the similarity profile

Similarity character and comparison budgets are explicit, and exhaustion raises an exception whilst restoring both active page positions; see FPdfDiff for scoring, thresholds and limits

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

The 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