> ## Documentation Index
> Fetch the complete documentation index at: https://docs.nemu.cc/llms.txt
> Use this file to discover all available pages before exploring further.

# Introduction

> PDF generation for Node and Bun with a declarative document API and a low level element API

`@nemu-ai/pdf` generates PDFs from code. It ships two APIs from one package that share a
single rendering engine, so you can describe a document with content blocks or place every
element by hand, and mix the two when you need to.

<CardGroup cols={2}>
  <Card title="Doc API" icon="layer-group" href="/packages/pdf/doc/overview">
    Declarative. Write a document as a list of content blocks and let the library handle
    layout, pagination, headers, and footers. Best for reports, articles, and invoices.
  </Card>

  <Card title="Document API" icon="ruler-combined" href="/packages/pdf/document/overview">
    Imperative. Place text, shapes, images, and containers at exact coordinates with flex and
    flow layout. Best for precise designs and custom layouts.
  </Card>
</CardGroup>

## Features

<CardGroup cols={2}>
  <Card title="Real font weights" icon="bold">
    Six variable fonts are bundled and auto registered. `font_weight` and markdown bold render
    genuine weights from thin to black.
  </Card>

  <Card title="LaTeX math" icon="square-root-variable">
    Block and inline formulas are typeset by MathJax into crisp vector paths, with selectable
    math fonts.
  </Card>

  <Card title="Native charts" icon="chart-column">
    Bar, line, area, pie, and donut charts render as vector graphics with no image step.
  </Card>

  <Card title="Tables and notes" icon="table">
    Tables with rich cells, callout notes, lists, code blocks, dividers, and images.
  </Card>

  <Card title="Layout engine" icon="objects-column">
    Flex and flow containers, z index layering, and explicit positioning in the low level API.
  </Card>

  <Card title="Portable" icon="node-js">
    Works on Node 18+ and Bun, in both ESM and CommonJS. Fonts and the font instancer are
    bundled.
  </Card>
</CardGroup>

## How the two APIs relate

`Doc` compiles its block tree down to the `Document` and `Page` element API and then calls
`build`. It adds no separate renderer. Anything `Doc` produces, you could also build by hand
with `Document`. Start with `Doc` for documents, and drop to `Document` when you need exact
control.

```ts theme={null}
import { Doc, Document } from "@nemu-ai/pdf";
```

## A first look

<CodeGroup>
  ```ts Doc API theme={null}
  import { Doc } from "@nemu-ai/pdf";

  const doc = new Doc({ page_size: "A4", margin: 54 });

  doc.page().content(
    { type: "heading", text: "Quarterly Report", level: 1 },
    { type: "paragraph", text: "Revenue grew across every region this quarter." },
  );

  await doc.build("report.pdf");
  ```

  ```ts Document API theme={null}
  import { Document } from "@nemu-ai/pdf";

  const pdf = new Document({ page_size: "A4", margin: 50 });
  const page = pdf.create_page();

  page.add(
    page.text({ content: "Invoice", style: { font_size: 28, font_weight: "bold" } }),
    page.text({ content: "Thank you for your business." }),
  );

  await pdf.build("invoice.pdf");
  ```
</CodeGroup>

<Card title="Install the package" icon="arrow-right" href="/packages/pdf/installation" horizontal>
  Add `@nemu-ai/pdf` to your project and render your first PDF.
</Card>
