PDFium Delphi Component Docs

Bounded PDF comparison helpers

FPdfDiff implements page alignment, UTF-16 text changes and connected visual regions used by CompareWith

AlignPdfDiffPages pairs exact text, geometry and visual fingerprints through a bounded longest common subsequence, then identifies remaining exact matches as moves and pairs unmatched gaps as modifications

Duplicate pages are paired deterministically; a page that moves and changes at the same time is not guaranteed to be identified as a move

BuildPdfDiffTextChanges reports zero-based UTF-16 offsets and lengths; character mode keeps surrogate pairs together and word mode groups whitespace separately from other characters

BuildPdfDiffPixelRegions groups connected changed tiles into exclusive-right/bottom pixel rectangles; these regions can include unchanged pixels inside a tile

Alignment accepts at most 4,096 pages per side and 16,777,216 cells; text accepts at most 65,536 tokens and 16,777,216 UTF-16 units, with explicit truncation when selected detail budgets are exhausted

Public declarations

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;