How I Built a 200-Page Red/Blue PDF Blueprint Overlay & Diff Tool 100% in Browser Canvas (Zero Backend)
Every week, construction estimators and paralegals run into the same frustrating problem: an architect drops Addendum 4 (200+ pages) forty-eight hours before bid day, or opposing counsel sends back a revised PDF contract
Every week, construction estimators and paralegals run into the same frustrating problem: an architect drops Addendum 4 (200+ pages) forty-eight hours before bid day, or opposing counsel sends back a revised PDF contract.
The existing options all have painful tradeoffs:
Enterprise suites like Bluebeam Revu moved to expensive annual per-seat subscriptions.
Free online PDF diff websites require uploading confidential bid sets or legal contracts to someone else's server.
Most desktop perpetual tools are Windows-only and blocked in locked-down corporate browser environments.
I wanted to see if a modern browser (Chrome, Edge, or Safari) could handle both 200-page text diffs and Bluebeam-style Red/Blue pixel overlays strictly inside local RAM β with zero backend servers and zero file uploads.
Here is the architecture behind RedlineZero and the three tricky engineering problems I had to solve.
- Reconstructing Readable Lines from pdfjs-dist (Not Raw Stream Order)
If you naively join page.getTextContent().items, PDFs often store text fragments out of visual order (headers, footers, and table columns jump around).
To make line-by-line diffs readable, I bucket TextItems by their PDF Y-coordinate (with a 3.5pt tolerance) and sort each horizontal row by X-coordinate:
ts
tokens.sort((a, b) => {
if (Math.abs(a.y - b.y) > 3.5) return b.y - a.y; // top-to-bottom
return a.x - b.x; // left-to-right
});
- Bounded LCS + Inline Word/Number Highlighting Without Freezing the Tab
When comparing a 200-page addendum, two things can kill UX:
Main-thread freezes: Extracting and diffing 200 pages synchronously locks the browser. Yielding every 4 pages (await new Promise(r => setTimeout(r, 0))) keeps a live progress bar silky smooth.
Whole-line highlights hide the actual change: Estimators don't want to scan two 30-word sentences to see what changed β they want to see 4,000 β 5,000 or $12,000 β $18,500 pop out in 0.2 seconds.
By trimming common prefixes/suffixes before running a Uint16Array LCS table (with a memory guard for gigantic pages) and then pairing adjacent remove + add lines for a secondary token-level diff, changed numbers and clauses light up immediately.
- Classic Red/Blue Pixel Blueprint Overlay in HTML5 Canvas
Text diffs are useless when an architect moves a partition wall or adds an HVAC diffuser on a vector/scanned floor plan.
For visual comparison, I render Page A and Page B onto two white-padded offscreen canvases (supporting an X/Y pixel alignment nudge for slightly shifted scans) and compute per-pixel luminance:
ts
const lumOld = 0.299 * dataOld[i] + 0.587 * dataOld[i + 1] + 0.114 * dataOld[i + 2];
const lumNew = 0.299 * dataNew[i] + 0.587 * dataNew[i + 1] + 0.114 * dataNew[i + 2];
if (Math.abs(lumOld - lumNew) <= threshold) {
// Unchanged ink fades to neutral gray so revisions pop
const avg = (lumOld + lumNew) * 0.5;
const faded = avg > 245 ? 255 : Math.min(245, Math.round(avg + (255 - avg) * 0.42));
out[i] = out[i + 1] = out[i + 2] = faded;
} else if (lumOld < lumNew) {
// Darker in Original => Removed => Vivid Red
out[i] = 220; out[i + 1] = 38; out[i + 2] = 38;
} else {
// Darker in Revised => Added => Vivid Blue
out[i] = 37; out[i + 1] = 99; out[i + 2] = 235;
}
Unchanged walls and gridlines fade softly to gray, deleted geometry turns crisp Red, and new additions turn Blue β with an instant Side-by-Side / Doc A / Doc B toggle right in the toolbar whenever overlapping text needs to be read clearly.
Try It Offline (No Signup Required)
You can test the full workflow right now with the built-in 3-page sample construction addendum (or your own PDFs β free up to 5 pages, zero uploads, works even if you disconnect your Wi-Fi after loading):
π https://diff.tensorvisualworks.com/
I'd love feedback from anyone who deals with large PDF revisions or scanned drawings β what edge cases break your current workflow?
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes β full credit and traffic to the original publisher.