If you try to export a printable floor plan from a browser app, the first instinct is almost always the wrong one: screenshot the <canvas> or <svg>, pass it to html2canvas or Puppeteer, and call "Print to PDF."
The result looks passable on a laptop monitor and fails immediately on a job site. A rasterized PNG blurs when zoomed to 400% at a cabinet corner, inflates file sizes on 24×36" ARCH D sheets, requires a 300 MB Chromium binary that cannot run on Cloudflare Workers, and — worst of all — destroys physical scale. When a framing carpenter or remodeler lays a triangular architectural scale ruler across a printed floor plan at 1/4" = 1'-0", a 14-foot wall must measure 3.500 inches on paper, not 3.31 inches because a browser added print margins and scaled to 94.6%.
In PlanCaliber, we compile 2-sheet and 5-sheet architectural blueprint packets (A-101 Dimensioned Floor Plan, A-102 Enlarged Kitchen & Bath Schedule, E-101 Screened-Back Electrical Plan, A-201 Exterior Elevations & Isometric Projection, and M-101 ANSI Z765 GLA & Material Takeoff) directly into pure vector PDF bytes using TypeScript and pdf-lib inside a Cloudflare Worker — with zero headless browser and sub-250ms execution time.
Here are the five concrete engineering problems we had to solve to make programmatic pdf-lib drawings print cleanly at true US architectural scale.
1. Exact Scale Math in PDF Points (Never "Fit-to-Page")
PDF coordinates are measured in PostScript points, where 1 inch = 72 points. That makes exact US architectural scale ratios clean rational constants:
-
1/4" = 1'-0"(1:48 scale):12 real inchesmaps to0.25 paper inches=18.0 pt. Therefore1 real inch = 1.500 pt. -
1/8" = 1'-0"(1:96 scale):12 real inchesmaps to0.125 paper inches=9.0 pt. Therefore1 real inch = 0.750 pt.
Instead of shrinking a drawing to fit an arbitrary margin (which produces unreadable scales like 1 : 53.4), a real CAD compiler holds ptPerIn locked to a standard scale and promotes the paper sheet size first:
interface TrueScaleSheetSpec { pageWidthPt: number; pageHeightPt: number; sheetSizeName: string; ptPerIn: number; scaleLabel: string; titleBlockWidthPt: number; } function selectTrueScaleSheet(widthIn: number, depthIn: number): TrueScaleSheetSpec { // Reserve 116" (~9'-8") of world-space padding for exterior dimension chains const paddedWidthIn = widthIn + 116; const paddedDepthIn = depthIn + 116; // Tier 1: 1/4" = 1'-0" (1.500 pt/in) on ANSI B 11" x 17" Tabloid (1224 x 792 pt) if (paddedWidthIn * 1.5 <= 940 && paddedDepthIn * 1.5 <= 640) { return { pageWidthPt: 1224, pageHeightPt: 792, sheetSizeName: 'ANSI B (11" x 17")', ptPerIn: 1.5, scaleLabel: `1/4" = 1'-0"`, titleBlockWidthPt: 214 }; } // Tier 2: 1/4" = 1'-0" (1.500 pt/in) on ARCH D 36" x 24" (2592 x 1728 pt) if (paddedWidthIn * 1.5 <= 2260 && paddedDepthIn * 1.5 <= 1560) { return { pageWidthPt: 2592, pageHeightPt: 1728, sheetSizeName: 'ARCH D (36" x 24")', ptPerIn: 1.5, scaleLabel: `1/4" = 1'-0"`, titleBlockWidthPt: 244 }; } // Tier 3: 1/8" = 1'-0" (0.750 pt/in) on ARCH D 36" x 24" return { pageWidthPt: 2592, pageHeightPt: 1728, sheetSizeName: 'ARCH D (36" x 24")', ptPerIn: 0.75, scaleLabel: `1/8" = 1'-0"`, titleBlockWidthPt: 244 }; } A kitchen remodel, bathroom suite, or 750 sq ft ADU fits on an office-printable 11"×17" Tabloid sheet at full 1/4" = 1'-0". A 2,400 sq ft ranch automatically promotes to 24"×36" ARCH D while staying at 1/4" = 1'-0". Only footprints exceeding ~125 feet step down to 1/8" = 1'-0". We also expose this sheet-sizing math interactively in our free Floor Plan Scale & Sheet Fit Calculator.
2. Filled Polygons and Y-Axis Inversion in pdf-lib
HTML Canvas and SVG place (0, 0) at the top-left with +Y pointing down. PDF places (0, 0) at the bottom-left with +Y pointing up. Worse, pdf-lib gives you drawLine, drawRectangle, drawCircle, and drawSvgPath, but no native drawPolygon helper for arbitrary non-convex L-shaped room fills or mitered wall poché.
The cleanest workaround is compiling any arbitrary PDF-space polygon directly into an SVG path string (M x y L ... Z) anchored at (0, pageHeightPt), where drawSvgPath re-applies SVG's Y-down offset relative to the top of the page:
function drawPolygonPdf( page: PDFPage, pageHeightPt: number, ptsPdf: Point2D[], options: { fillColor?: Color; borderColor?: Color; borderWidth?: number; opacity?: number; } ): void { if (ptsPdf.length < 3) return; const parts: string[] = []; for (let i = 0; i < ptsPdf.length; i++) { const sx = Number(ptsPdf[i].x.toFixed(3)); const sy = Number((pageHeightPt - ptsPdf[i].y).toFixed(3)); parts.push(`${i === 0 ? 'M' : 'L'} ${sx} ${sy}`); } parts.push('Z'); page.drawSvgPath(parts.join(' '), { x: 0, y: pageHeightPt, color: options.fillColor, borderColor: options.borderColor, borderWidth: options.borderWidth ?? 0, opacity: options.opacity }); } That 20-line helper renders mitered exterior wall poché, tinted wet-zone room fills, kitchen island footprints, and crisp isometric roof facets as resolution-independent vector paths — zooming to 1600% in Acrobat or Preview stays razor-sharp.
3. Preventing WinAnsi Crashes on Real User Input
Here is a bug that waits silently in production until your first real homeowner types a project title from macOS or iOS: 11’ x 7.5’ Bathroom — Proposed.
pdf-lib's built-in StandardFonts.Helvetica and StandardFonts.Courier use WinAnsi encoding, which throws an uncaught runtime exception the moment it encounters Unicode right single quotes (\u2019), em-dashes (\u2014), prime symbols (\u2032), or multiplication signs (\u00D7). Meanwhile, embedding a full 400 KB TrueType subset font slows down cold Cloudflare Worker isolates.
For clean architectural lettering, normalizing user strings to WinAnsi-safe ASCII and measuring exact glyph widths before drawing prevents both encoding crashes and overflowing title-block cells:
function safePdfText(input: string): string { return input .replace(/[\u2014\u2013]/g, '-') .replace(/[\u2018\u2019\u2032]/g, "'") .replace(/[\u201C\u201D\u2033]/g, '"') .replace(/\u00D7/g, 'x') .replace(/\u00B7/g, '|') .replace(/[^\x20-\x7E]/g, ''); } function fitPdfText(input: string, font: PDFFont, size: number, maxWidthPt: number): string { const clean = safePdfText(input).trim(); if (!clean || font.widthOfTextAtSize(clean, size) <= maxWidthPt) return clean; const ellipsis = '...'; const target = Math.max(8, maxWidthPt - font.widthOfTextAtSize(ellipsis, size)); const words = clean.split(/\s+/); let acc = ''; for (const w of words) { const cand = acc ? `${acc} ${w}` : w; if (font.widthOfTextAtSize(cand, size) <= target) acc = cand; else break; } return acc ? `${acc}${ellipsis}` : `${clean.slice(0, 1)}${ellipsis}`; } Every room label, fixture schedule row, and title-block header passes through safePdfText + fitPdfText (or a multi-line wrapPdfLines helper), guaranteeing zero uncaught font exceptions and zero overlapping text across every sheet.
4. Visual Hierarchy Across a 5-Sheet Architectural Packet
Real construction drawings do not dump walls, furniture, dimensions, switches, and material tables onto one cluttered page. Because our compiler draws directly from one canonical SolvedPlan geometry graph, generating specialized sheets is just toggling layer weights and opacity:
- Sheet
A-101— Dimensioned Floor Plan: Full-ink wall poché (6"exterior /4.5"interior), mitered wall corners, door swings (with special sectional-panel rendering for wide16'overhead garage doors so they never draw absurd 16-foot swing arcs), 3-tier exterior dimension chains (overall, structural, openings), graphic scale bar, and north arrow. - Sheet
A-102— Enlarged Kitchen, Bath & Fixture Layout: Door, window, and cabinetry schedule keyed by fixture codes (VAN-48,ISL-36x84,DW-24) with NKBA/IRC clearance callouts. - Sheet
E-101— Electrical & Lighting Plan: The exact same architectural plan rendered in screened-back light gray (rgb(0.68, 0.685, 0.7)), so high-contrast GFCI outlets, recessed cans, ceiling fans, and curved switch legs pop immediately for an electrician. - Sheet
A-201— Elevations & Isometric View: Projected orthographic wall heights, window sill/head elevations, and a pure-vector 3D isometric cutaway. - Sheet
M-101— ANSI Z765 GLA & Material Takeoff: Automated separation of heated living area versus non-GLA garage/shop area, linear feet of framing, estimated 16" O.C. studs, and 4×8 drywall sheets.
Every sheet carries a clear preliminary space-planning disclaimer reminding builders that final structural permitting requires on-site field verification by a licensed professional.
5. Performance & Edge Testing
Running our full 5-sheet vector PDF compiler inside Node 24 tests (tests/cad.test.ts) completes in roughly 170–210 ms for a multi-room residential plan and produces a compact 30–75 KB vector PDF — small enough to compile on demand in a single Cloudflare Worker request with zero queue, zero headless browser container, and zero cold-start timeouts.
If you want to inspect the actual vector output in your own PDF viewer (zoom in to 800% on the dimension ticks and door arcs), you can download an unlocked live sample directly from our compiler here:
- Download Sample Compiled Vector Blueprint PDF
- Explore the Blueprint & Layered AutoCAD R12 .DXF Studio
- Browse 20 Starter Floor Plan Templates
- Draft a Plan Free in PlanCaliber Studio
Built with TypeScript, SvelteKit, and pdf-lib on Cloudflare Workers. If you have hit other edge cases generating vector CAD PDFs without Chromium — custom line dashes, font subsetting, or multi-page tiling — drop a note in the comments.
