# @veztraa/report-renderer

PDF rendering engine for ReportForge. Converts a template JSON + data object into a PDF buffer using `@react-pdf/renderer` — pure Node.js, zero Chromium, zero Python.

Works in **Node.js and the browser** from a single install. Fonts (12 families, 44 weights) are bundled inside the package and registered automatically — no `Font.register()` calls needed.

## Installation

```bash
npm install @veztraa/report-renderer
```

## Usage

### Node.js (Express, Next.js API route, CLI, etc.)

```ts
import { render } from "@veztraa/report-renderer";

const pdf = await render(template, data);

// Save to file
import fs from "fs";
fs.writeFileSync("report.pdf", pdf);

// Stream in Express
app.get("/report", async (req, res) => {
  const pdf = await render(template, data);
  res.setHeader("Content-Type", "application/pdf");
  res.setHeader("Content-Disposition", "attachment; filename=report.pdf");
  res.send(pdf);
});

// Or stream directly
import { renderStream } from "@veztraa/report-renderer";
const stream = await renderStream(template, data);
stream.pipe(res);
```

### Browser (React + Vite)

```ts
import { render } from "@veztraa/report-renderer";

async function downloadPdf() {
  const pdf = await render(template, data);
  const blob = new Blob([pdf], { type: "application/pdf" });
  const url = URL.createObjectURL(blob);
  window.open(url); // or trigger download
}
```

> Vite automatically picks the browser build (via the `browser` export condition). Fonts are embedded as base64 data URIs — no network requests, works offline.

## API

```ts
// Render to Buffer (Node.js) or Uint8Array (browser)
render(template: Template, data?: Record<string, unknown>): Promise<Buffer>

// Render to readable stream (Node.js only)
renderStream(template: Template, data?: Record<string, unknown>): Promise<NodeJS.ReadableStream>
```

## Bundled Fonts

All fonts are pre-registered and available in templates via `style.fontFamily`:

| Family | Weights |
|---|---|
| Roboto | 400, 700, italic |
| Open Sans | 400, 700, italic |
| Lato | 400, 700, italic |
| Montserrat | 400, 700, italic |
| Inter | 400, 700 |
| Poppins | 400, 700, italic |
| Nunito | 400, 700, italic |
| Raleway | 400, 700, italic |
| Ubuntu | 400, 700, italic |
| Playfair Display | 400, 700, italic |
| Merriweather | 400, 700, italic |
| Source Code Pro | 400, 700 |

## Template Format

See [`@veztraa/report-core`](https://www.npmjs.com/package/@veztraa/report-core) for the full template schema and expression syntax.

## License

MIT © [Veztraa Innovations](https://veztraa.com)
