Someone would place their signature perfectly. Confirm it looked right. Sign. Download.
And the signature would be shifted — sometimes right, sometimes off by 30-40 pixels, always upward. Never consistent enough to reproduce on demand, which made it brutal to debug.
I tried patching the sign page. Then the PDF generator. Then the field editor. Each fix "worked" on some documents and quietly failed on others. I was chasing a symptom without understanding the disease.
The actual root cause, once I finally found it: I was assuming every PDF page was A4 sized (1122px tall). Most weren't. US Letter is a different aspect ratio. So is Legal. So is anything a user exports from Word, Canva, or their own tools.
Every field's position was stored as a percentage — which is the right approach — but that percentage was being calculated against a fake, assumed page height on the way in, and the real page height on the way out. Two different denominators for the same number. The math was quietly wrong from the very first click, and nothing about it looked wrong until you compared the signed PDF to the original.
The fix ended up being the same principle every serious e-signature platform uses under the hood: extract each page's real dimensions the moment a PDF is uploaded, store that as the single source of truth, and make every part of the pipeline — the editor, the signer's view, the final PDF — reference that same number. No assumptions. No fallback constants pretending to be facts.
It took going file by file, tracing the exact same coordinate through five different places it got calculated, to find where the story diverged.
Shipping it fixed. Confirmed with a real Letter-size document, signature at the bottom of the page — the exact case that used to break.
Small bug, real lesson: when something is "almost right," the fix is rarely a patch. It's usually a wrong assumption sitting quietly upstream of everything else.