# Keep Together

Keeps children on the same PDF page.

> For the complete documentation index, see [llms.txt](/llms.txt). Markdown variants are available by appending `.md` to any docs URL. An agent skill is available at [/.well-known/agent-skills/site-skill.md](/.well-known/agent-skills/site-skill.md).

## Installation

```bash
npx shadcn@latest add @angular-pdfcn/takumi/keep-together
```

To install manually, add the dependencies:

```bash
npm install takumi-pdf @takumi-rs/helpers
```

Then copy these files into your project and update the import paths to match your setup:

- `components/pdf/keep-together/keep-together.ts`
- `lib/resolve-color.ts`
- `components/pdf/theme-provider.ts`
- `lib/pdf-renderer.ts`
- `lib/pdf-primitives.ts`
- `lib/render.ts`
- `lib/pdf-themes/professional.ts`
- `lib/pdf-themes/primitives.ts`
- `types/pdf-themes.ts`
- `types/pdf-components.ts`

## Usage

```ts
import { Component } from "@angular/core";

import { PdfHeading } from "@/components/pdf/heading/heading";
import { PdfKeepTogether } from "@/components/pdf/keep-together/keep-together";
import { PdfSection } from "@/components/pdf/section/section";
import { PdfText } from "@/components/pdf/text/text";
import { PdfcnThemeProvider } from "@/components/pdf/theme-provider";
import {
  TakumiDocument,
  TakumiPage,
} from "@/lib/pdf-primitives";

@Component({
  imports: [
    TakumiDocument,
    TakumiPage,
    PdfcnThemeProvider,
    PdfHeading,
    PdfKeepTogether,
    PdfSection,
    PdfText,
  ],
  template: `
    <takumi-document>
      <takumi-page size="A4">
        <pdf-theme-provider>
          <pdf-section spacing="none">
            <pdf-keep-together>
              <pdf-heading [level]="2">Section Title</pdf-heading>
              <pdf-section variant="callout" padding="sm">
                <pdf-text noMargin
                  >This heading and callout stay together as one atomic block
                  when the document flows onto another page.</pdf-text
                >
              </pdf-section>
            </pdf-keep-together>
            <pdf-keep-together [minPresenceAhead]="80">
              <pdf-heading [level]="3">Subsection Heading</pdf-heading>
              <pdf-text
                >Reserve enough room before starting this subsection so its
                heading is never stranded at the bottom of a page.</pdf-text
              >
            </pdf-keep-together>
            <pdf-keep-together>
              <pdf-heading [level]="4">Signature Block</pdf-heading>
              <pdf-section variant="card" padding="sm">
                <pdf-text noMargin>Approved by: ____________________</pdf-text>
              </pdf-section>
            </pdf-keep-together>
          </pdf-section>
        </pdf-theme-provider>
      </takumi-page>
    </takumi-document>
  `,
})
export class KeepTogetherDemo {}
```

## API Reference

### PdfKeepTogether

| Input              | Type     | Default |
| ------------------ | -------- | ------- |
| `minPresenceAhead` | `number` | -       |
| `style`            | `Style`  | -       |

The content to keep on one page is projected content.