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

# Pages

> Merge, split, select, delete, insert, compose, and rotate the pages of PDFs.

Each operation below is a [stage](https://docs.chromiumly.dev/stages.md) for `stages` lists, and a method on `PDF` for a single operation. Options of type *pages* take a [page selection](https://docs.chromiumly.dev/stages.md#page-selections) such as `"1-3"`, `"odd"` or `"!last"`.

## merge

Appends the PDFs into one, in the **alphanumeric order** of their names. The result takes the name of the first PDF. Bookmarks are kept and point at the merged pages.

```typescript theme={null}
import { PDF } from "chromiumly";

const merged = await PDF.merge({
  files: ["path/to/1-cover.pdf", "path/to/2-body.pdf"],
});
```

As a stage: `{ op: "merge" }`. On `LibreOffice.convert()`, it joins the exported documents into one PDF. For a bookmark per merged file, add a `set-bookmarks` stage after it.

## split

Cuts each PDF into several, which come back in a ZIP: `report_0.pdf`, `report_1.pdf`… Set `every` or `ranges`, not both.

| Option | Type | Description |
| - | - | - |
| `every` | `number` | Cuts every this many pages, at least 1 |
| `ranges` | `string[]` | One PDF per entry, each a page selection (`"1-3"`) |

```typescript theme={null}
const zip = await PDF.split({ files: ["path/to/report.pdf"], ranges: ["1", "2-3"] });
const pairs = await PDF.split({ files: ["path/to/report.pdf"], every: 2 });
```

In a `stages` list, the stages after `split` run on each part.

## select and delete

`select` keeps the `pages` you list, in the order you list them; `delete` removes them.

```typescript theme={null}
const firstAndThird = await PDF.select({ files: ["path/to/report.pdf"], pages: "1,3" });
const withoutCover = await PDF.delete({ files: ["path/to/report.pdf"], pages: "1" });
```

To pull a few pages into one PDF, use `select`; to get one PDF per range, use `split`.

## insert

Inserts the pages of another PDF.

| Option | Type | Description |
| - | - | - |
| `source` | [`StageFile`](https://docs.chromiumly.dev/stages#files-a-stage-needs) | The PDF whose pages to insert (required) |
| `at` | `number` | Inserts after this page; `0` inserts before the first (default `0`) |
| `sourcePages` | pages | The pages of `source` to insert (default `all`) |

```typescript theme={null}
const withAnnex = await PDF.insert({
  files: ["path/to/report.pdf"],
  source: "path/to/annex.pdf",
  at: 2,
});
```

## compose

Draws pages of the PDFs on new pages of the size you choose: a label, a packing slip, a sheet of several pages. The result is one new PDF, named after the first input.

| Option | Type | Description |
| - | - | - |
| `paperSize` | `string` | `"A3"`, `"A4"`, `"A5"`, `"B4"`, `"B5"`, `"Letter"`, `"Legal"` or `"Tabloid"` |
| `paperWidth` / `paperHeight` | `string` | A length such as `"6in"` or `"15cm"`; overrides the side `paperSize` sets |
| `placements` | `ComposePlacement[]` | One per drawn page (required) |

Set `paperSize`, or both `paperWidth` and `paperHeight`. Each placement takes:

* `source` — the **name of an input PDF** to draw from; leave it out with one input. Every input PDF must be placed.
* `sourcePage` — the page of `source`, `1` by default.
* `page` — the new page to draw on, `1` by default. A page no placement names comes out blank.
* `x`, `y` — the bottom-left corner of the drawn page, in points from the bottom-left of the new page (72 points to the inch).
* `scale` — `1` by default; `rotation` — degrees, counter-clockwise around `x` and `y`.

```typescript theme={null}
const label = await PDF.compose({
  files: [
    { file: reportBuffer, name: "report.pdf" },
    { file: annexBuffer, name: "annex.pdf" },
  ],
  paperWidth: "6in",
  paperHeight: "5in",
  placements: [
    { source: "report.pdf", x: 0, y: 180, scale: 0.25 },
    { source: "annex.pdf", x: 0, y: 0, scale: 0.25 },
  ],
});
```

Annotations, form fields, bookmarks, tags and metadata of the source pages are not drawn. Add `set-metadata`, `set-bookmarks` or `autotag` stages after `compose` to give the result its own.

## rotate

Sets the rotation of pages. Viewers turn them clockwise.

| Option | Type | Description |
| - | - | - |
| `angle` | `number` | A multiple of 90, such as `90` or `-90` (required) |
| `pages` | pages | The pages to rotate (default `all`) |

```typescript theme={null}
const rotated = await PDF.rotate({ files: ["path/to/scan.pdf"], angle: 90, pages: "2-4" });
```

See [Reference — PDF](https://docs.chromiumly.dev/reference/pdf.md) and [Reference — stages](https://docs.chromiumly.dev/reference/stages.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.