惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google DeepMind News
Google DeepMind News
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
小众软件
小众软件
博客园 - 司徒正美
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Jina AI
Jina AI
Hugging Face - Blog
Hugging Face - Blog
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
雷峰网
雷峰网
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
T
Tailwind CSS Blog
Martin Fowler
Martin Fowler
I
InfoQ
The GitHub Blog
The GitHub Blog
有赞技术团队
有赞技术团队
The Cloudflare Blog
罗磊的独立博客

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
How I Built a Zero-Dependency PDF Generator in Next.js fo...
Ewald · 2026-05-02 · via DEV Community

Ewald

Generating PDFs in a modern web app is usually a massive headache. If you've ever tried to spin up a headless browser like Puppeteer on a serverless function, or wrestled with the strict layouts of pdfmake or jsPDF, you know the pain.

I recently hit this exact wall while building PropSign, a POPIA-compliant electronic document signing platform for South African real estate agents.

We needed to generate legally binding, ECTA-compliant PDF mandates and lease agreements on the fly. The PDF needed to look identical to the web view, support custom agency branding, and include complex audit trails.

Instead of adding heavy server-side dependencies, I decided to use the most underrated PDF engine available: the user's own browser.

Here is how I built a zero-dependency PDF generator using Next.js 15, Tailwind CSS, and window.print().

The Architecture

PropSign is a Next.js App Router application backed by Convex for the database and Clerk for authentication.

When an agent needs to download a signed mandate, they don't hit an API endpoint that generates a file. Instead, they hit a dedicated Next.js route: /dashboard/documents/[id]/print.

1. The Dedicated Print Route

The secret sauce is isolating the document in its own route layout. You do not want your navigation bars, sidebars, or chat widgets rendering in the PDF.

I created a specific print page that fetches the document data from Convex and renders it in a pure, unstyled container.

// app/dashboard/documents/[id]/print/page.tsx

"use client";
import { useEffect } from "react";
import { useQuery } from "convex/react";
import { api } from "@/convex/_generated/api";

export default function PrintPage({ params }: { params: { id: string } }) {
  const document = useQuery(api.documents.getById, { id: params.id });

  useEffect(() => {
    // Automatically trigger the print dialog once the data loads
    if (document) {
       setTimeout(() => {
         window.print();
       }, 500); 
    }
  }, [document]);

  if (!document) return <div>Loading...</div>;

  return (
    <div className="print:m-0 print:p-0 bg-white text-black">
      {/* Force page breaks for legal clauses */}
      <div className="break-after-page">
        <h1 className="text-2xl font-bold">{document.title}</h1>
        <div dangerouslySetInnerHTML={{ __html: document.body }} />
      </div>

      {/* Audit Trail Section */}
      <div className="mt-10 pt-10 border-t border-gray-300 break-inside-avoid">
         <h3 className="font-bold">ECTA Audit Trail</h3>
         <p>Signed by: {document.signatoryName}</p>
         <p>IP Address: {document.ipAddress}</p>
         <p>Timestamp: {new Date(document.signedAt).toISOString()}</p>
      </div>
    </div>
  );
}

Enter fullscreen mode Exit fullscreen mode

2. Forcing Background Graphics

By default, Chrome and Safari will strip out background colors and images when printing. For a SaaS like PropSign where agency branding and logos are crucial, this is a dealbreaker.

You can force the browser to render them by adding this single line of CSS to your global stylesheet:

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
}

Enter fullscreen mode Exit fullscreen mode

Why this approach wins

  1. Zero Server Costs: Generating PDFs on a server uses serious compute. Offloading this to the client's browser means it costs me absolutely nothing.
  2. Instant Rendering: There is no waiting for a serverless function to cold-boot or a queue to process. The user clicks "Download," the route loads in milliseconds, and the PDF dialog appears.
  3. Perfect Fidelity: What the client sees on the screen when they sign is exactly what the PDF looks like, down to the pixel.
  4. Pushing for a Greener Earth: The real estate industry is notorious for printing massive stacks of paper for every mandate and FICA request. By keeping the entire workflow digital and generating perfect digital PDFs only when absolutely necessary, this architecture directly supports PropSign's mission to push agencies toward a fully paperless, environmentally friendly future.

The Takeaway

If you are building a B2B SaaS and need document generation, don't immediately reach for a heavy backend library. Modern browser print engines are incredibly powerful if you structure your HTML and CSS correctly.

If you are curious about how we handle the rest of the architecture, including mandatory POPIA consent flows and AI document summaries, you can check out our guide on PropSign's POPIA Compliance Architecture here.

What are you currently using for PDF generation in your stack? Let me know in the comments!