How PaperForge Works
Unlike traditional printable websites that store megabytes of static pre-made PDF files or rely on server-side headless browsers, PaperForge is an entirely static, client-side application hosted on Cloudflare Pages.
Every printable PDF you download is synthesized dynamically in your browser in fractions of a second using deterministic mathematics and open-source vector rendering libraries.
1. The Deterministic Intermediate Representation (IR)
At the core of PaperForge is a lightweight layout engine defined in src/lib/print/ir.ts. The engine models documents as an abstract syntax tree of drawing primitives in PDF points (72 points per inch, origin at top-left):
- Document: Top-level metadata and an ordered array of pages.
- Page: Width, height, and an array of vector operations.
- Operations: Primitive elements including
rect,roundedRect,line,circle,path, andtext.
Every template on PaperForge is a pure mathematical function:(options: TemplateOptions) => Document.
Given the exact same options (or random seed), the generator returns the exact same vector instructions every single time.
2. Build-Time Font Metrics: Eliminating Browser Drift
A frequent issue in browser-based document generation is typography drift: because different operating systems (Windows, macOS, Linux, Android) utilize different font rendering engines and font rasterizers, text measured via HTML5 Canvas or the DOM will wrap at different word positions depending on your machine.
PaperForge solves this completely. During our static production build, an automated script reads our four self-hosted typography files (Inter, Lora, Caveat, and Nunito) using OpenType font parsing. It computes the exact horizontal advance widths and vertical metrics for every Latin character and packages them into metrics.json.
When you customize a template, our layout engine measures string widths and wraps lines using these mathematical metrics. Layout calculations never query the browser DOM, guaranteeing identical line breaks whether you are on an iPhone, a Chromebook, or a high-end desktop workstation.
3. Twin Renderers: Live Preview Meets Vector Export
Our architecture consumes the intermediate representation through two distinct renderers:
- SVG Preview Renderer: Converts page operations into an SVG string. SVG paths and elements are rendered natively inside the browser preview panel, providing instant visual feedback at 60 frames per second as you toggle settings.
- PDF-Lib Vector Exporter: When you click "Download PDF," the application lazy-loads the
pdf-libandfontkitlibraries. It registers our self-hosted TrueType font buffers, translates IR coordinates into PDF coordinate space, and exports a vector PDF file directly to your browser's download manager.
4. Pure Integer Calendar Mathematics
Our calendar engine calculates date grids and leap year determinations using integer arithmetic on the proleptic Gregorian calendar. It never invokes JavaScript's native new Date() object for calendar math, completely eliminating timezone-related shift bugs (such as a calendar day shifting into the previous month due to UTC offsets).
5. Absolute Anonymity and Privacy
Because all document generation occurs locally within your browser's JavaScript runtime:
- Your personal notes, to-do lists, and recipient names are never sent over the network.
- We do not operate backend servers, serverless functions, or analytics databases.
- Generated PDF documents have their metadata scrubbed clean: Title, Author, Creator, and Producer are explicitly locked to PaperForge, with all creation and modification timestamps fixed to a standard date.