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

# PDF overview

> Run stages on existing PDFs, one by one or as a pipe, and read PDFs, with the PDF class.

The `PDF` class wraps Gotenberg’s [PDF routes](https://gotenberg.dev/docs/pdf/pipe) to work on PDFs you already have. It does not create PDFs from HTML, URLs or documents; use the [Chromium](https://docs.chromiumly.dev/chromium/overview.md) or [LibreOffice](https://docs.chromiumly.dev/libreoffice.md) routes for that, with their own [`stages`](https://docs.chromiumly.dev/stages).

## Run several stages: pipe

`PDF.pipe()` runs a list of [stages](https://docs.chromiumly.dev/stages.md) on the PDFs you send, in order:

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

const buffer = await PDF.pipe({
  files: ["path/to/report.pdf"],
  stages: [
    { op: "select", pages: "1-2" },
    { op: "stamp-text", text: "DRAFT", x: 72, y: 72, fontSize: 24 },
    { op: "optimize" },
  ],
});
```

It answers the PDF, or a ZIP when several files come out: several inputs without a `merge`, or a `split`.

## Run one stage

Each stage also has its own method, which takes the stage's options next to the request options:

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

| Method | Stage | Page |
| - | - | - |
| `merge`, `split`, `select`, `delete`, `insert`, `compose`, `rotate` | The page operations | [Pages](https://docs.chromiumly.dev/pdf/pages.md) |
| `stampText`, `stampImage`, `stampPdf` | `stamp-text`, `stamp-image`, `stamp-pdf` | [Stamps](https://docs.chromiumly.dev/pdf/stamps.md) |
| `setMetadata`, `setBookmarks` | `set-metadata`, `set-bookmarks` | [Metadata and bookmarks](https://docs.chromiumly.dev/pdf/metadata.md) |
| `setForm`, `flattenForm` | `set-form`, `flatten-form` | [Forms](https://docs.chromiumly.dev/pdf/forms.md) |
| `encrypt`, `decrypt`, `sign`, `timestamp`, `redact` | The security stages | [Security](https://docs.chromiumly.dev/pdf/security.md) |
| `remediate`, `autotag`, `convertColors`, `flattenTransparency` | The conformance stages | [Conformance](https://docs.chromiumly.dev/pdf/conformance.md) |
| `attach`, `detach`, `extractAttachments` | The attachment stages | [Attachments](https://docs.chromiumly.dev/pdf/attachments.md) |
| `render`, `extractText`, `optimize` | `render`, `extract-text`, `optimize` | [Render and extract](https://docs.chromiumly.dev/pdf/render-extract.md) |

## Read PDFs

The read methods answer JSON, which Chromiumly parses and types: one entry per PDF, under its file name.

| Method | Answers | Page |
| - | - | - |
| `info` | Page count, PDF version, and whether it's encrypted, tagged, linearized or holds form fields | [below](#info) |
| `metadata` | Title, author, subject, keywords, creator, producer and dates | [Metadata](https://docs.chromiumly.dev/pdf/metadata.md#read-the-metadata) |
| `bookmarks` | The bookmarks, nested | [Metadata](https://docs.chromiumly.dev/pdf/metadata.md#bookmarks) |
| `attachments` | The embedded files | [Attachments](https://docs.chromiumly.dev/pdf/attachments.md) |
| `form` | The form fields and the values they take | [Forms](https://docs.chromiumly.dev/pdf/forms.md#list-the-fields) |
| `validate` | Conformance to PDF/A, PDF/UA or Factur-X, and the violations | [Conformance](https://docs.chromiumly.dev/pdf/conformance.md#validate) |

They take `files`, `archives`, `downloadFrom`, an optional `password` for encrypted PDFs, and `trace`. They don't take a webhook or an output filename.

### info

```typescript theme={null}
const info = await PDF.info({ files: ["path/to/report.pdf"] });
// {
//   "report.pdf": {
//     pages: 3, version: "1.7", encrypted: false,
//     tagged: false, linearized: false, formFields: false
//   }
// }
```

## Inputs

Every method takes `files`, and may leave it out when `archives` or `downloadFrom` bring the PDFs (see [Files and downloads](https://docs.chromiumly.dev/advanced/files-and-downloads.md)). Each entry is a `PdfInput`:

```typescript theme={null}
type PdfInput =
  | PathLikeOrReadStream // a .pdf path keeps its base name; a Buffer or ReadStream is named fileNN.pdf after its position
  | { file: PathLikeOrReadStream; name: string }; // uploaded under `name`
```

Gotenberg takes the PDFs in the **alphanumeric order** of their names, and stages (such as `compose`) and the read methods refer to them by name. Name them after the order you want:

```typescript theme={null}
const merged = await PDF.merge({
  files: [
    { file: coverBuffer, name: "1-cover.pdf" },
    { file: bodyBuffer, name: "2-body.pdf" },
  ],
});
```

Every method except the read methods also takes `webhook` (see [Webhooks](https://docs.chromiumly.dev/advanced/webhooks.md)) and `outputFilename` and `trace` (see [Request tracing](https://docs.chromiumly.dev/advanced/request-tracing.md)).

## Save a result

`PDF.generate()` writes a buffer to the `__generated__` directory under the current working directory:

```typescript theme={null}
await PDF.generate("report.pdf", buffer);
```

See [Reference — PDF](https://docs.chromiumly.dev/reference/pdf.md) for every method's signature.


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