
How to generate a PDF from HTML in Node.js (without Puppeteer)
How to Generate a PDF from HTML in Node.js (Without Puppeteer) The canonical Node.js answer for HTML-to-PDF is Puppeteer: spin up a headless Chromium, navigate to a page or set content, call page.pdf() . It works, but it pulls Chromium into your dependency tree, adds 200–400MB to your deployment, and breaks in serverless environments unless you configure a Chromium layer. Here's the one-fetch alternative: Basic usage import fs from ' fs ' ; const html = `<!DOCTYPE html> <html> <head> <style> body { font-family: system-ui, sans-serif; padding: 40px; } h1 { font-size: 24px; margin-bottom: 8px; } .amount { font-size: 32px; font-weight: bold; color: #111; } </style> </head> <body> <h1>Invoice #1042</h1> <p>Due: March 1, 2026</p> <div class="amount">$429.00</div> </body> </html>` ; const res = await fetch ( ' https://pagebolt.dev/api/v1/pdf ' , { method : ' POST ' , headers : { ' x-api-key ' : process . env . PAGEBOLT_API_KEY , ' Content-Type ' : ' application/json ' }, body : JSON . string
Continue reading on Dev.to JavaScript
Opens in a new tab

