# Pages and sections as PDF

A section of a Récit site (a category of its navigation) prints as **one PDF**: its pages in the
order of the navigation, without the menu, the sidebars or the buttons, Mermaid diagrams drawn,
links between its pages turned into links inside the file. The command prints the site's build as it
is: no second build, no script of your own. The same command prints the decks the site publishes,
one PDF each, downloadable from the deck's page ([The published decks](#4-the-published-decks)).

:::caution{title="Preview"}

Like the site framework and `@recit/site-stories`, the PDF of docs pages is a **preview**, outside
the 1.0 contract ([Stability](/documentation/reference/stability)).

:::

## 1. Say what prints (recit.config.ts)

The `pdf` key of the site's `docs` section lists the sections, each by the label of its category (or
the route of one of its pages):

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  docs: {
    files: ["./pages/**/*.mdx"],
    pdf: {
      sections: ["Lorem guide"],
      titlePage: true,
      toc: true,
      baseUrl: "https://docs.example.com",
    },
  },
  navigation: [
    {
      type: "category",
      label: "Lorem guide",
      items: ["guide/context", "guide/model", "guide/rules"],
    },
  ],
});
```

The section must be there when the site is built: it is what makes each page hand its navigation
over to the PDF (`?print=1`) and show the download button. `defineConfig` of `recit/config` adds
`@recit/site-stories`, which does both.

## 2. Build, then print

```bash
recit-site build                            # the site, into dist/
recit export --to pdf --site .              # every section of docs.pdf, and the decks of publish.pdf
recit export --to pdf --site . --section "Lorem guide"
recit export --to pdf --site . --page /guide/context
```

Each PDF is written into the build (`dist/pdf/<section>.pdf` by default) and listed in
`dist/exports.json`. Deploy `dist/` as usual: the PDF goes with it. Chromium comes from Playwright,
an optional peer of the CLI (`pnpm add -D playwright && npx playwright install chromium`); print in
CI, never on the host that serves the site.

## 3. The download button

On every page a PDF of `exports.json` holds, a button above the content offers it ("Download “…”
(PDF)"). It reads `exports.json` when the page opens. A site with `docs.pdf`, `publish.pdf` or
`publish.entries[].exports` writes an empty `exports.json` (`files: []`) at build time, sealed like
every other file on an encrypted site, and `recit export --to pdf --site` (or
`recit export --site . --entries`) fills it in: a preview before the export shows no button and logs
no 404, and never links to a PDF that is not there.

On a site encrypted with a password (`access.mode: "encrypted"`,
[Password protection](/documentation/configuration/password)) the button works the same once the
password is given. The PDF is encrypted in the build like every other file, so the button does not
let the browser save the file it is served: it fetches the PDF through the page, which decrypts it,
and saves the decrypted copy under its own name (`docs.pdf`, not `RCT1…` bytes). While it works the
button says so ("Preparing the download…"), and a download that fails says that too. The decrypted
copy exists only in the memory of the tab until it is saved: no cache, no server, nothing in clear
in the build.

### Link a PDF from a page: `<PdfDownload>`

Any PDF of the build, the docs' or a deck's, can be linked from an MDX page with the same download,
encrypted site or not:

```mdx title="pages/catalogue.mdx"
<PdfDownload path="pdf/docs.pdf" title="Lorem guide" />
<PdfDownload path="presentations/lorem.pdf">The Lorem deck (PDF)</PdfDownload>
```

A published deck's PDF is at `<routePrefix>/<slug>.pdf` by default, next to its page
(`/presentations/lorem` → `presentations/lorem.pdf`), so a catalogue of decks links each one by that
path ([The published decks](#4-the-published-decks)). On a multilingual site each language has its
own PDF next to its own page: `presentations/lorem.pdf` for the default language,
`fr/presentations/lorem.pdf` for French, and under `i18n.routing: "prefix-always"` the default
language too (`en/presentations/lorem.pdf`): the path to give `<PdfDownload>`.

| Prop         | Default                    | Description                                                                          |
| ------------ | -------------------------- | ------------------------------------------------------------------------------------ |
| `path`       | —                          | the file from the root of the site, without the base path (`pdf/docs.pdf`)           |
| `title`      | —                          | names the file in the default label: `Download “…” (PDF)`, `Télécharger « … » (PDF)` |
| `fileName`   | the last segment of `path` | the name the file is saved under                                                     |
| `appearance` | `link`                     | `button` frames it like the button above the pages                                   |
| `lang`       | `metadata.lang`            | the language of the default label and of the messages                                |
| children     | the default label          | the text of the link                                                                 |

On a site in clear it is a plain `<a href download>`. It does not check that the file exists: link
the PDF your CI prints. A PDF printed at commit and injected by the build
([prebuilt PDFs](/documentation/configuration/pdf-prebuilt), on a site whose host has no Chromium)
is at the same path, so the same `path` works: the build reseals it with its own key and lists it in
the sealed files of its envelope (`recit-access.json`), and the page decrypts it like the others.

### Hide or move the button: `docs.pdf.button`

The button sits above the content by default. `docs.pdf.button` moves it under the content or hides
it, for a site that offers its PDFs with `<PdfDownload>` only (a catalogue page, a summary):

```ts title="recit.config.ts"
export default defineConfig({
  docs: {
    pdf: {
      sections: ["Lorem"],
      button: "bottom", // true or "top" (default): above; "bottom": under; false: none
    },
  },
});
```

The print does not depend on it: with `button: false` the docs PDFs are still printed and listed in
`exports.json`, and a page can still offer them with `<PdfDownload>` (by path). Hide the button
through this key, never through a class of the component: its class names are internal and change
without notice.

## 4. The published decks

The decks a site publishes (`publish.dir` and `publish.entries`,
[Stories in a site](/documentation/integrations/site-stories)) print too, one PDF per deck, when the
site sets `publish.pdf`:

```ts title="recit.config.ts"
export default defineConfig({
  publish: {
    routePrefix: "/presentations",
    entries: [
      { file: "./talks/01-kickoff/deck.md", slug: "01-kickoff" },
      { file: "./talks/02-review/deck.md", slug: "02-review" },
      { file: "./talks/03-internal/deck.md", slug: "03-internal" },
    ],
    // true prints every published deck with each deck's own options
    pdf: {
      decks: ["01-kickoff", "02-review"], // default: every published deck
      notes: false,
      colorMode: "light",
    },
  },
});
```

| Key         | Default                    | What it does                                                                                                                                  |
| ----------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `decks`     | every published deck       | The slugs of the decks printed (a slug that no deck has is an error naming the others)                                                        |
| `notes`     | the deck's own (`false`)   | A page of speaker notes after each slide that has notes                                                                                       |
| `colorMode` | the deck's own             | `light` or `dark`                                                                                                                             |
| `output`    | `<routePrefix>/{slug}.pdf` | Where each PDF goes in the build, relative to it: `{slug}`, `{locale}`. On a multilingual site, see [Multilingual sites](#multilingual-sites) |

Each deck prints the way `recit export --to pdf deck.md` prints it, with the `recit.config.*` found
next to it (its theme, its `deck.pdf`): `publish.pdf` sits over that config, and the deck's own
`pdf:` front matter over `publish.pdf`, so one deck can keep its notes while the others drop them.

```bash
recit export --to pdf --site .                         # docs.pdf and publish.pdf
recit export --to pdf --site . --decks                 # the decks only
recit export --to pdf --site . --deck 01-kickoff       # one deck
recit export --to pdf --site . --decks --notes         # the decks, with their notes
```

`--decks` and `--deck` print even without `publish.pdf`; `--section`, `--page` and `--scope` print
the docs only. Each PDF is written into the build and listed in its `exports.json` with the deck's
route; on an encrypted site the PDFs and `exports.json` are encrypted with the build's key, like the
docs' PDF. With `@recit/pptx` installed (preview, see [Exporting](/formats/deck/exporting)),
`recit export --to pptx --site .` (or `--deck <slug>`) writes each published deck's `.pptx` next to
its page and lists it in `exports.json` (`--prebuilt` puts it into `recit-pdf/`).

For any published story in `publish.entries` that sets `exports` (`"images"`, `"pdf"`, `"mp4"`),
`recit export --site . --entries` (with no `--to`) writes its PDF at `<routePrefix>/<slug>.pdf`, its
images under `<routePrefix>/<slug>/images/`, and its film at `<routePrefix>/<slug>.mp4` (with its
captions and transcript alongside it; `"mp4"` requires Chromium and ffmpeg, like `recit render`, and
fails on a format that has no film) inside the build, and lists every file in `exports.json` (with
the story's route on the PDF). Each entry's `slug` must stay inside the build and resolve to a
unique output path, or the command fails with an error. A nested `slug` (`2026/launch`) writes its
files into the matching subfolder under `<routePrefix>/`. On a multilingual site (`i18n`), each
language the story has a variant for (`story.fr.md` next to `story.md`) is exported too, under its
page's language prefix (`<locale>/<routePrefix>/<slug>…`, and `<defaultLocale>/…` too under
`i18n.routing: "prefix-always"`), and listed in `exports.json` with its `locale`. On an encrypted
site (`access.mode: "encrypted"`), `--entries` seals every exported file and `exports.json` with the
build's key (requiring the password variable, with nothing written in clear in `dist/`, like
`--to pdf --site`). `--entries` refuses `--prebuilt`, `--locale`, `--all-locales`, `--no-manifest`
and `--output`. A site that declares `publish.entries[].exports` alone still reads `exports.json`
and shows its exported media. On an unsealed site, each entry's PDF also gets its first-page PNG
`preview` in the build and in `exports.json`.

A story's own PDF (`recit export --to pdf <story>`) — like an entry's PDF exported with `--entries`
— gets a PNG of its first page next to it, and its entry in `exports.json` names it in `preview`:
`preview.path` (relative to `exports.json`), `preview.width` and `preview.height` in pixels. The
docs' PDFs, the decks printed with `--to pdf --site`, the variants (`--variants`) and any PDF of an
encrypted site have no `preview`.

**On the deck's page**, the toolbar then offers "Download the deck (PDF)" ("Télécharger le deck
(PDF)" in French), also in the "Options" menu the toolbar folds into under 480 px. It reads
`exports.json` when the page opens, on a site that sets `publish.pdf` or
`publish.entries[].exports`: a deck without a PDF shows nothing. On an encrypted site it downloads
the decrypted file, as the docs' button does. The key **P** downloads it too, and the deck's
shortcut help (**?**) lists "Download the PDF" in its Tools group ("Télécharger le PDF"), only when
the deck has a PDF.

A deck embedded in a page with `<StoryEmbed>` offers it only when asked, with `pdf`:

```mdx
<StoryEmbed slug="01-kickoff" pdf />
```

### Multilingual sites

On a site with `i18n`, a deck is published in its default language and in each language it has a
variant for (`deck.fr.md` next to `deck.md`; every language of a JSON story), one page per language,
and the export prints **one PDF per published language**, each the way that language's page shows
the deck (its variant, its title, its `lang`). Each PDF follows the page's route:

| `i18n.routing`                    | Default language                                         | Another language (`fr`)                                  |
| --------------------------------- | -------------------------------------------------------- | -------------------------------------------------------- |
| `prefix-except-default` (default) | `/presentations/lorem` → `presentations/lorem.pdf`       | `/fr/presentations/lorem` → `fr/presentations/lorem.pdf` |
| `prefix-always`                   | `/en/presentations/lorem` → `en/presentations/lorem.pdf` | `/fr/presentations/lorem` → `fr/presentations/lorem.pdf` |

Each one is listed in `exports.json` with its own route and `locale`, so the toolbar of the French
page offers the French PDF. With an `output` pattern, `{locale}` names the language; a pattern
without it holds the default language's PDF, and each other language's goes under `<locale>/` of it
(`output: "pdf/{slug}.pdf"` → `pdf/lorem.pdf` and `fr/pdf/lorem.pdf`), so that no two languages
write the same file. The pattern is relative to the build, a leading `./` or `/` included, for every
language alike (`"/pdf/{slug}.pdf"` is `pdf/lorem.pdf` and `fr/pdf/lorem.pdf`). `--deck lorem`
prints every language of that deck.

## Language

The PDF speaks the language of the site: `metadata.lang` of recit.config (else the `<html lang>` of
its pages, else `en`). It is the `lang` of the printed document, so the `/Lang` of the tagged PDF
that screen readers read, the `locale` of its entry in `exports.json` and `{locale}` in `output`;
the contents are titled in it ("Sommaire" in French), and so are the page's own labels ("Dernière
modification le…") and the download button ("Télécharger « … » (PDF)").

```ts title="recit.config.ts"
export default defineConfig({
  metadata: { title: "%s | Lorem Docs", lang: "fr" },
  docs: { pdf: { sections: ["Guide Lorem"] } },
});
```

Build the site again after changing it: the pages carry the language the PDF prints.

## Options

`docs.pdf`, checked by `DocsPdfOptionsSchema` of `@recit/core` (and by the `config` JSON Schema, for
an editor). The command line overrides the config.

| Option         | Default                                         | What it does                                                                                          |
| -------------- | ----------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| `sections`     | `[]`                                            | The categories printed: a label, or the route of one of their pages (`--section`)                     |
| `scope`        | `section`                                       | `section`: one PDF per category; `page`: one PDF per page of those categories (`--scope`)             |
| `page.size`    | `A4`                                            | `A4`, `A5`, `A3`, `A2`, `Letter` or `{ width, height }` (`--page-size`)                               |
| `page.margins` | `20mm` top and bottom, `24mm` left and right    | One length, or one per side                                                                           |
| `titlePage`    | `false`                                         | A first page with the section's title and the site's                                                  |
| `toc`          | `false`                                         | Contents after the title page, as links: `true` lists the pages and their `h2`, `{ depth: n }` deeper |
| `header`       | none                                            | `{ start, center, end }`, with `{title}`, `{page}`, `{pages}`                                         |
| `footer`       | `{ start: "{title}", end: "{page} / {pages}" }` | The same tokens; `{}` removes it                                                                      |
| `colorMode`    | `light`                                         | `light` or `dark`: the pages render in it, Mermaid included (`--color-mode`)                          |
| `output`       | `pdf/{slug}.pdf`                                | File name in the build: `{slug}` of the section or page, `{locale}`, `{format}` (`-o` for one file)   |
| `baseUrl`      | the site's `canonicalUrlOrigin`                 | Where the site is published: a link to a page outside the PDF points there; without it, plain text    |
| `button`       | `true` (above the content)                      | The download button of a page: `true` or `top` above, `bottom` under, `false` none (not printed)      |
| `outline`      | `true`                                          | Bookmarks from the headings                                                                           |
| `tagged`       | `true`                                          | Tagged PDF, for screen readers                                                                        |

## What the print takes care of

- **Only the content.** Navigation, sidebars, the page's contents, search, "Copy page", the previous
  and next links and the anchors of the headings are left out, and so is anything marked
  `data-pagefind-ignore` or `data-recit-print="hide"`.
- **Diagrams drawn.** Each page is printed once nothing in it is still loading: a Mermaid diagram is
  awaited until its SVG replaces its spinner, never a fixed delay. Every `id` of a page gets the
  page's prefix, so two diagrams (`mermaid-0` on each page) keep their own styles.
- **Pages and sheets.** Each page starts on a new sheet; a heading never stays alone at the bottom
  of a sheet; a table row, a diagram, a picture or a quotation is not split; a table repeats its
  header row.
- **Links.** A link to a page of the PDF leads to it inside the file; a link to a page outside it
  becomes `baseUrl` + its route, or plain text; an external link stays clickable.
- **Type and margins.** The site's font is embedded; code wraps, and nothing wider than the text
  (code, table, picture) runs into the margins.
