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

> PDF — run stages on existing PDFs, one by one or as a pipe, and read PDFs.

Static class. No constructor; call its methods on `PDF`. Every method resolves to a `Promise`.

## Request options

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

type PdfRequestOptions = {
  files?: PdfInput[]; // optional when archives or downloadFrom bring the PDFs
  archives?: PathLikeOrReadStream[];
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
};

/** A single-stage method's options: the request options and the stage's options, without `op`. */
type PdfStageRouteOptions<Op extends StageOp> = PdfRequestOptions & StageOptions<Op>;
```

## pipe(options)

Runs `stages` on the PDFs, in order. At least one stage is required.

```typescript theme={null}
PDF.pipe(options: PdfRequestOptions & { stages: Stage[] }): Promise<Buffer>
```

## Single-stage methods

Each posts to `/forms/pdf/<op>` and resolves to the result: a PDF, or a ZIP or another file type where the stage makes one.

| Method | Stage | Options type |
| - | - | - |
| `merge(options)` | `merge` | `PdfRequestOptions` |
| `split(options)` | `split` | `PdfStageRouteOptions<"split">` — exactly one of `every` or `ranges` |
| `select(options)` | `select` | `PdfStageRouteOptions<"select">` |
| `delete(options)` | `delete` | `PdfStageRouteOptions<"delete">` |
| `insert(options)` | `insert` | `PdfStageRouteOptions<"insert">` |
| `compose(options)` | `compose` | `PdfStageRouteOptions<"compose">` |
| `rotate(options)` | `rotate` | `PdfStageRouteOptions<"rotate">` |
| `stampText(options)` | `stamp-text` | `PdfStageRouteOptions<"stamp-text">` |
| `stampImage(options)` | `stamp-image` | `PdfStageRouteOptions<"stamp-image">` |
| `stampPdf(options)` | `stamp-pdf` | `PdfStageRouteOptions<"stamp-pdf">` |
| `setMetadata(options)` | `set-metadata` | `PdfStageRouteOptions<"set-metadata">` |
| `setBookmarks(options)` | `set-bookmarks` | `PdfStageRouteOptions<"set-bookmarks">` |
| `setForm(options)` | `set-form` | `PdfStageRouteOptions<"set-form">` |
| `flattenForm(options)` | `flatten-form` | `PdfRequestOptions` |
| `flattenTransparency(options)` | `flatten-transparency` | `PdfRequestOptions` |
| `convertColors(options)` | `convert-colors` | `PdfStageRouteOptions<"convert-colors">` |
| `redact(options)` | `redact` | `PdfStageRouteOptions<"redact">` |
| `autotag(options)` | `autotag` | `PdfRequestOptions` |
| `attach(options)` | `attach` | `PdfStageRouteOptions<"attach">` |
| `detach(options)` | `detach` | `PdfStageRouteOptions<"detach">` |
| `extractAttachments(options)` | `extract-attachments` | `PdfStageRouteOptions<"extract-attachments">` |
| `extractText(options)` | `extract-text` | `PdfStageRouteOptions<"extract-text">` |
| `optimize(options)` | `optimize` | `PdfStageRouteOptions<"optimize">` |
| `encrypt(options)` | `encrypt` | `PdfStageRouteOptions<"encrypt">` — at least one password |
| `decrypt(options)` | `decrypt` | `PdfStageRouteOptions<"decrypt">` |
| `remediate(options)` | `remediate` | `PdfStageRouteOptions<"remediate">` |
| `sign(options)` | `sign` | `PdfStageRouteOptions<"sign">` |
| `timestamp(options)` | `timestamp` | `PdfStageRouteOptions<"timestamp">` |
| `render(options)` | `render` | `PdfStageRouteOptions<"render">` |

All return `Promise<Buffer>`. The stages' options are listed in [Reference — stages](https://docs.chromiumly.dev/reference/stages.md).

```typescript theme={null}
const encrypted = await PDF.encrypt({
  files: ["path/to/report.pdf"],
  userPassword: "open-me",
  permissions: { print: false },
  outputFilename: "report-locked",
});
```

## Read methods

They answer one entry per PDF, under its file name, parsed from Gotenberg's JSON. They take no webhook and no output filename.

```typescript theme={null}
type PdfReadOptions = {
  files?: PdfInput[];
  archives?: PathLikeOrReadStream[];
  downloadFrom?: DownloadFrom;
  password?: string; // opens encrypted PDFs
  trace?: string;
};

type PdfReadResult<T> = Record<string, T>;
```

| Method | Resolves to |
| - | - |
| `info(options: PdfReadOptions)` | `PdfReadResult<PdfInfo>` |
| `metadata(options: PdfReadOptions)` | `PdfReadResult<PdfMetadata>` |
| `bookmarks(options: PdfReadOptions)` | `PdfReadResult<Bookmark[]>` |
| `attachments(options: PdfReadOptions)` | `PdfReadResult<PdfAttachment[]>` |
| `form(options: PdfReadOptions & { pages?: string })` | `PdfReadResult<PdfFormField[]>` |
| `validate(options: PdfReadOptions & { profile: ConformanceProfiles })` | `PdfReadResult<PdfValidation>` |

```typescript theme={null}
type PdfInfo = {
  pages: number;
  version: string;
  encrypted: boolean;
  tagged: boolean;
  linearized: boolean;
  formFields: boolean;
};

type PdfMetadata = {
  title?: string;
  author?: string;
  subject?: string;
  keywords?: string;
  creator?: string;
  producer?: string;
  creationDate?: string;
  modDate?: string;
};

type PdfAttachment = {
  name: string;
  mimeType?: string;
  relationship?: AttachmentRelationship;
};

type PdfFormField = {
  name: string;
  type: "text" | "checkbox" | "radio" | "button" | "combo" | "list" | "signature";
  value: string | string[];
  pages: number[];
  states?: string[];
  options?: string[];
  readOnly?: boolean;
  required?: boolean;
  multiSelect?: boolean;
  editable?: boolean;
  maxLength?: number;
};

type PdfValidation = {
  profile: ConformanceProfiles;
  compliant: boolean;
  violations: PdfViolation[];
};

type PdfViolation = {
  specification: string;
  clause: string;
  testNumber: number;
  description: string;
  context: string;
  severity: "fatal" | "warning";
};
```

## generate(filename, buffer)

Writes a buffer to `__generated__/<filename>` under the current working directory.

```typescript theme={null}
PDF.generate(filename: string, buffer: Buffer): Promise<void>
```


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