PDF Drawing Diff — CAD Drawing Revision Comparison
Compare revisions of a CAD-exported PDF without reducing the drawing to pixels. The Python for Excel notebook extracts vector paths and text with PyMuPDF, registers the two pages, removes unchanged primitives, deterministically matches moved or modified elements, groups nearby changes, and publishes a review log into Excel.
Result preview
The built-in validation pair simulates a civil drawing re-export with a known +5 / -3 drawing-unit whole-sheet translation plus changed linework and labels. Registration recovers that drift exactly in the baseline. After alignment, the deterministic comparison reports 15 exact matches, 1 moved match, 3 fuzzy matches, 2 added primitives, 4 modified primitives, and 2 grouped change regions instead of treating the entire sheet as different.
What this template does
- Accepts a previous and revised vector PDF in the Python for Excel task pane.
- Compares one selected page from each revision at a time.
- Rejects raster-only, encrypted, unreadable, or extremely sparse pages rather than silently falling back to image diffing.
- Extracts generic
LINE,POLYLINE,RECT,CURVE,FILLED_SHAPE, andTEXTprimitives from PyMuPDF. - Builds location-independent content signatures and positioned signatures using configurable geometric quantization.
- Estimates translation, rotation, and uniform scale from unique text and vector anchors with deterministic seeded RANSAC.
- Removes exact registered matches before more expensive matching.
- Recovers moved primitives by content signature and performs spatially filtered deterministic fuzzy matching with Hungarian assignment.
- Produces typed added, removed, moved, geometry, text, and optional style changes.
- Groups nearby primitive changes into review regions and shows synchronized previous/revised/diff crops.
- Exports
changes.json, an annotated revised PDF, and an AI review ZIP containing before/after/diff crops.
Why Python
A vector drawing comparison needs PDF parsing, geometric normalization, transform estimation, spatial candidate generation, assignment optimization, typed delta construction, and image/PDF export. Python can express this pipeline directly with PyMuPDF, NumPy, and SciPy while Excel remains the operational review surface for thresholds, summary metrics, grouped regions, and the detailed change log.
The matching system is deliberately deterministic. It does not use PyTorch, graph neural networks, OCR, or a vision model to discover differences. Semantic interpretation can be added later from the exported evidence bundle, after exact vector geometry has established where the drawing changed.
Try it live
The notebook starts with a generated one-page before/after pair so the workflow is immediately visible. Upload two related vector PDFs in the task pane to replace the demo, choose the pages, and press Compare to refresh the result.
Operating workflow
Author: a CAD automation, engineering systems, or construction-technology analyst maintains extraction rules, registration tolerances, deterministic matching logic, ground-truth fixtures, and publication/export contracts.
Workbook user: an engineer, estimator, coordinator, or reviewer selects two drawing revisions, chooses the corresponding pages, reviews grouped changes in Excel and the task pane, then exports evidence for downstream technical review when needed.
For recurring revision review, save the finished notebook to open in App mode and verify that the intended reviewer can complete the comparison without author intervention. App mode changes presentation; it does not change workbook permissions, source access, document confidentiality, or trust.
Download the Excel template
Inputs and assumptions
Dashboard!C6:D14 contains the durable matching configuration used to initialize the task-pane controls:
- position tolerance;
- geometry tolerance;
- move distance;
- fuzzy candidate radius;
- match threshold;
- maximum registration residual as a fraction of sheet diagonal;
- change-region clustering distance;
- optional style-change detection.
The MVP compares one selected page from Revision A against one selected page from Revision B. The PDFs must contain vector drawing content or text that PyMuPDF can extract. Raster scans are intentionally out of scope.
Notebook implementation
The notebook binds the durable worksheet thresholds through one displayed Boardflare input widget:
inputs = bf.inputs(
thresholds=bf.ref("Dashboard!C6:D14", headers=True),
)The task pane adds two PDF upload controls, page selectors, a compare button, advanced threshold controls, a grouped-region selector, synchronized before/revised/diff crops, and download buttons. Workbook-facing results are published as summary, registration, regions, and changes.
How the calculation/model works
Each PyMuPDF drawing path becomes a generic vector primitive and each text span becomes a TEXT primitive. Geometry is converted immediately to plain Python numbers, lists, and dictionaries. A content signature quantizes translation-independent geometry, dimensions, style, and text; a positioned signature adds quantized location.
Registration first pairs unique identical text strings and unique vector signatures. Seeded RANSAC estimates a similarity transform (translation, rotation, and uniform scale) and declines the comparison when alignment confidence is insufficient. The previous revision is transformed into the revised coordinate system before any change classification.
Tier 1 removes identical positioned signatures. Tier 2 matches equal content signatures at a different registered position, which allows a moved object to remain one modification instead of a removal plus addition. Tier 3 creates only spatially nearby compatible candidates, scores geometry/style/location/text-context similarity, partitions the sparse candidate graph, and runs scipy.optimize.linear_sum_assignment within each component. Unmatched primitives become added or removed records; altered matches receive movement, geometry, text, and optional style flags.
Finally, nearby deltas are clustered into change regions. The workbook shows the first 50 regions and first 100 primitive changes, while changes.json contains the complete result for the selected pages.
Validation / expected results
The deterministic fixture is generated as vector PDF content directly inside the notebook. It includes stable text/vector anchors, whole-sheet export translation, a moved line, changed pipe text, changed geometry, an added structure/line segment, and revised structure text. The template validation gate runs this pair through the real notebook logic and the real offline Boardflare/Univer browser runtime.
A worksheet threshold scenario raises the fuzzy match threshold from 0.72 to 0.95. The expected result changes from three fuzzy matches to zero, with the affected text/geometry pairs becoming explicit additions and removals. This confirms that workbook controls drive real notebook recalculation rather than replaying static output.
Limitations
This is an MVP primitive-level comparison, not a full CAD object model. One engineering object may be exported as many PDF paths, so region grouping is intentionally the primary review unit. The current workflow does not provide OCR, raster diffing, automatic multi-sheet matching, architectural/civil semantic classes, automatic takeoff, cloud storage, or LLM interpretation. Curves are compared from the vector control points exposed by PyMuPDF rather than reconstructed into source-CAD entities.
Matching thresholds require calibration against real drawing sets. Dense sheets can still produce many unmatched primitives after exact filtering, and browser memory/runtime should be validated against the largest intended production pages. A reliable registration failure declines the comparison rather than forcing a misleading diff.
When to use this approach
Use this pattern when drawings are CAD-exported vector PDFs, reviewers need exact localization and machine-readable deltas, and confidentiality or auditability makes a deterministic local comparison preferable to uploading full drawings to a vision service. It is especially useful as a first-stage detector that can later hand grounded regions and exact geometry to a downstream engineering review model.