> ## 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.

# Quickstart

> Render your first PDF with the Doc API and the Document API

This page builds one small PDF with each API. Both write a file and are awaited.

## With the Doc API

Describe the document as content blocks, set role styles once, and call `build`.

<Steps>
  <Step title="Create a Doc">
    ```ts theme={null}
    import { Doc } from "@nemu-ai/pdf";

    const doc = new Doc({ page_size: "A4", margin: 54, padding: 10 });
    ```
  </Step>

  <Step title="Set role styles">
    Styles assigned per role apply to every block of that type.

    ```ts theme={null}
    doc.set_style({
      heading: { font_family: "inter", color: "#111827" },
      paragraph: { font_family: "source-serif-4", font_size: 11.5, line_height: 1.6 },
      link: { color: "#2563eb" },
    });
    ```
  </Step>

  <Step title="Add content">
    ```ts theme={null}
    doc.page().content(
      { type: "heading", text: "Quarterly Report", level: 1 },
      { type: "paragraph", text: "Revenue grew across every region this quarter." },
      { type: "note", variant: "info", title: "Note", text: "Figures are unaudited." },
    );
    ```
  </Step>

  <Step title="Build the file">
    ```ts theme={null}
    await doc.build("report.pdf");
    ```
  </Step>
</Steps>

The full script:

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

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

doc.set_style({
  heading: { font_family: "inter", color: "#111827" },
  paragraph: { font_family: "source-serif-4", font_size: 11.5, line_height: 1.6 },
  link: { color: "#2563eb" },
});

doc.page().content(
  { type: "heading", text: "Quarterly Report", level: 1 },
  { type: "paragraph", text: "Revenue grew across every region this quarter." },
  { type: "note", variant: "info", title: "Note", text: "Figures are unaudited." },
);

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

<Card title="Explore the Doc API" icon="layer-group" href="/packages/pdf/doc/overview" horizontal>
  Blocks, inline content, styling, fonts, formulas, tables, charts, and more.
</Card>

## With the Document API

Build elements with the page factories, then place them with `page.add`.

```ts 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.", style: { color: "#6b7280" } }),
);

await pdf.build("invoice.pdf");
```

<Warning>
  Page factories like `page.text` build an element but do not place it. Add what you build with
  `page.add` or a container's `add`, or it will not render.
</Warning>

<Card title="Explore the Document API" icon="ruler-combined" href="/packages/pdf/document/overview" horizontal>
  Elements, containers, layout, tables, themes, and positioning.
</Card>

## Choosing an API

<CardGroup cols={2}>
  <Card title="Use Doc when" icon="check">
    You are writing a document: a report, an article, an invoice. You want pagination, headers,
    and footers handled for you.
  </Card>

  <Card title="Use Document when" icon="check">
    You need exact coordinates, custom layouts, overlapping elements, or per element control.
  </Card>
</CardGroup>
