Next.js (App Router)
Use a Route Handler that returns application/pdf. Nebula is Node-only (native sharp / @resvg/resvg-js) — use the Node.js runtime, not the Edge runtime.
Example route
Section titled “Example route”app/api/report/route.ts:
import { PdfEngine, Page, Text } from 'nebula-pdf-engine';import { readFileSync } from 'fs';import { join } from 'path';
export const runtime = 'nodejs';
const font = readFileSync(join(process.cwd(), 'fonts/Inter-Regular.ttf'));const engine = new PdfEngine({ fonts: [{ name: 'Inter', data: font, weight: 400 }],});
export async function GET() { const pdf = await engine.generate( <Page size="A4" padding={40}> <Text style={{ fontSize: 24 }}>Next.js Report</Text> </Page>, );
return new Response(pdf, { headers: { 'Content-Type': 'application/pdf', 'Content-Disposition': 'inline; filename="report.pdf"', }, });}Ensure tsconfig uses jsxImportSource: "preact" for files that contain Nebula JSX, or generate with createElement / h.