Quick Start
Install
Section titled “Install”npm install nebula-pdf-engineNote: This package requires native dependencies sharp and @resvg/resvg-js.
Install Preact as a dev dependency so TypeScript can resolve JSX types (runtime Preact is bundled):
npm install -D preactConfigure tsconfig.json:
{ "compilerOptions": { "jsx": "react-jsx", "jsxImportSource": "preact" }}Generate a PDF
Section titled “Generate a PDF”import { PdfEngine, Page, Text, Image } from 'nebula-pdf-engine';import * as fs from 'fs';
const engine = new PdfEngine({ fonts: [ { name: 'Inter', data: fs.readFileSync('./fonts/Inter-Regular.ttf'), weight: 400 }, ], devicePixelRatio: 2,});
const pdfBuffer = await engine.generate( <Page size="A4" padding={40}> <Text style={{ fontSize: 32, marginBottom: 20 }}>Hello Nebula!</Text> <Image src="https://example.com/logo.png" width={100} height={50} /> <Text style={{ marginTop: 20 }}> This content will automatically flow across multiple pages if it is too long. </Text> </Page>,);
fs.writeFileSync('output.pdf', pdfBuffer);Fonts are required. PdfEngine throws if fonts is empty.
Without JSX
Section titled “Without JSX”Use createElement (alias h) in .ts files:
import { PdfEngine, Page, Text, createElement } from 'nebula-pdf-engine';
const pdf = await engine.generate( createElement( Page, { size: 'A4' }, createElement(Text, { style: { fontSize: 20 } }, 'Hello Workspace!'), ),);Next steps
Section titled “Next steps”- Examples — downloadable statement + receipt (CodeSandbox)
- Tables — schema-driven data tables
- TypeScript & JSX — JSX config details
- Next.js — App Router route handlers