Express / Node.js
import express from 'express';import { PdfEngine, Page, Text, h } from 'nebula-pdf-engine';import fs from 'fs';
const app = express();const engine = new PdfEngine({ fonts: [{ name: 'Inter', data: fs.readFileSync('./fonts/Inter-Regular.ttf'), weight: 400 }],});
app.get('/invoice.pdf', async (_req, res) => { const pdf = await engine.generate( h(Page, { size: 'A4', padding: 40 }, h(Text, { style: { fontSize: 20 } }, 'Invoice')), );
res.setHeader('Content-Type', 'application/pdf'); res.setHeader('Content-Disposition', 'attachment; filename="invoice.pdf"'); res.send(pdf);});
app.listen(3000);generate() returns a Node Buffer. Use res.send(buffer) or res.end(buffer) — there is no streaming API yet.