Skip to content

Semantic PDF Diff

SIDHARTH SINGH edited this page Dec 3, 2026 · 1 revision

Semantic PDF Diff & Redline Output (diffPdfs)

Comparing contracts, quotes, or policy drafts with image/pixel diffs breaks whenever a paragraph wraps onto a new page or reflows downward by half an inch. Semantic diffing solves this purely in TypeScript without Poppler or ImageMagick.

Three Diff Layers

  • Text Diff: Runs word, character, or line Myers LCS comparisons per page while optionally ignoring whitespace churn.
  • Layout Move Detection: Compares coordinate boxes from extractPositionedText() so identical blocks shifted beyond moveThresholdPt (15 pt default) report accurately as moved (blocksMoved) rather than noisy delete+insert pairs.
  • Resource Diff: Audits structural drift in page counts, embedded font names, image counts, and metadata properties.

Producing a Visual Redline Review PDF

import { diffPdfs, buildRedlinePdf } from 'onex-pdf';

const report = diffPdfs(oldPdf, newPdf, {
  granularity: 'word',
  ignore: { whitespace: true, metadata: true },
});

const redlinePdf = buildRedlinePdf(oldPdf, newPdf);

buildRedlinePdf() overlays translucent green boxes onto added spans, red boxes + strikethrough rules onto removed spans, and amber outlines onto moved elements—isolated inside q ... Q graphics blocks with /ExtGState opacity.

Clone this wiki locally