Back to Articles

Digital Contract Signing: PDF Manipulation with PDF-lib and AWS S3 Storage

How to build a PDF contract signing platform using PDF-lib for dynamic field placement, cryptographic signature validation, and AWS S3 for tamper-proof document storage.

Digital Contract Signing: PDF Manipulation with PDF-lib and AWS S3 Storage

DocuSigner lets companies upload contracts, place signature fields, and collect legally binding e-signatures entirely in the browser.


1. Dynamic PDF Field Placement

Using PDF-lib, we overlay interactive signature boxes onto existing PDF documents:

typescript
import { PDFDocument, rgb } from 'pdf-lib'; async function addSignatureField(pdfBytes: Uint8Array, x: number, y: number) { const pdfDoc = await PDFDocument.load(pdfBytes); const page = pdfDoc.getPages()[0]; page.drawRectangle({ x, y, width: 200, height: 50, borderColor: rgb(0, 0.5, 1), borderWidth: 2 }); page.drawText('Sign Here', { x: x + 10, y: y + 15, size: 12, color: rgb(0.5, 0.5, 0.5) }); return pdfDoc.save(); }

2. Cryptographic Signature Sealing

Once signed, the document is hashed (SHA-256) and the hash is stored alongside the signature. Any post-signing tampering invalidates the hash.


3. Audit Trail Logging

Every action (upload, view, sign) is logged with timestamps, IP addresses, and user agents for legal compliance.


Summary

PDF-lib enables browser-based document manipulation while cryptographic hashing ensures signed contracts cannot be tampered with after execution.