FPdfDiff supplies the page alignment, UTF-16 text-change and connected visual-region routines behind CompareWith
AlignPdfDiffPages uses a resource-limited longest common subsequence to pair matching text, geometry and visual fingerprints; it treats remaining exact matches as moves, then pairs unmatched gaps as modifications
Repeated pages receive deterministic pairings; a page moved and edited together need not be recognised as a move
BuildPdfDiffTextChanges supplies zero-based UTF-16 offsets and lengths; character mode never separates a surrogate pair, and word mode groups whitespace apart from other characters
BuildPdfDiffPixelRegions combines connected changed tiles into pixel rectangles with exclusive right and bottom edges; an unchanged pixel inside a tile may still lie within the returned region
Alignment permits 4,096 pages on either side and 16,777,216 cells; text processing permits 65,536 tokens and 16,777,216 UTF-16 units, and explicitly reports truncation when a chosen detail budget runs out
type
TPdfDiffPageKind= (dpkMatched, dpkModified, dpkMoved, dpkInserted, dpkDeleted);
TPdfDiffTextMode= (dtmNone, dtmCharacters, dtmWords);
TPdfDiffPageSignature= record
Text: WideString;
VisualHash: UInt64;
Width, Height: Single;
Rotation: Integer;
end;
TPdfDiffPageSignatures= array of TPdfDiffPageSignature;
TPdfDiffPagePair= record
LeftPageIndex, RightPageIndex: Integer;
Kind: TPdfDiffPageKind;
end;
TPdfDiffPagePairs= array of TPdfDiffPagePair;
// Offsets and lengths count UTF-16 code units, starting at zero
TPdfDiffTextChange= record
LeftStart, LeftLength, RightStart, RightLength: Integer;
end;
TPdfDiffTextChanges= array of TPdfDiffTextChange;
TPdfDiffPixelRegion= record
Left, Top, Right, Bottom: Integer;
end;
TPdfDiffPixelRegions= array of TPdfDiffPixelRegion;
function AlignPdfDiffPages(const Left, Right: TPdfDiffPageSignatures;
MaxCells: Integer): TPdfDiffPagePairs;
function BuildPdfDiffTextChanges(const Left, Right: WideString;
Mode: TPdfDiffTextMode; MaxCells, MaxTokens: Integer;
out Truncated: Boolean): TPdfDiffTextChanges;
function BuildPdfDiffPixelRegions(const Mask: TBytes; Width, Height,
TileSize, MaxRegions: Integer; out Truncated: Boolean): TPdfDiffPixelRegions;