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

# PDFEngines

> Static methods for convert, merge, split, rotate, watermark, stamp, metadata, bookmarks, flatten, encrypt, embed, facturX, and generate.

All methods are static. They use the configured endpoint (and auth) from `Chromiumly.configure()`. Every method also accepts `downloadFrom`, `webhook`, and `outputFilename`/`trace` — see [Request tracing](https://docs.chromiumly.dev/v6/advanced/request-tracing.md).

## convert(options)

Convert PDFs to PDF/A and/or PDF/UA. At least one of `pdfa` or `pdfUA` is required.

```typescript theme={null}
PDFEngines.convert({
  files: PathLikeOrReadStream[];
  pdfa?: PdfFormat;
  pdfUA?: boolean;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## merge(options)

Merge multiple PDFs into one.

```typescript theme={null}
PDFEngines.merge({
  files: PathLikeOrReadStream[];
  pdfa?: PdfFormat;
  pdfUA?: boolean;
  metadata?: Metadata;
  flatten?: boolean;
  bookmarks?: Bookmark[] | Record<string, Bookmark[]>;
  autoIndexBookmarks?: boolean;
  userPassword?: string;
  ownerPassword?: string;
  allowPrinting?: boolean;
  allowCopying?: boolean;
  allowModifying?: boolean;
  allowAnnotating?: boolean;
  allowFillingForms?: boolean;
  allowAssembling?: boolean;
  watermark?: PdfEngineWatermark;
  stamp?: PdfEngineStamp;
  rotate?: PdfEngineRotate;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

`bookmarks` sets a final bookmark list (or a filename-keyed map applied before merging, with page indexes offset automatically). `autoIndexBookmarks` instead auto-extracts and offsets each input's existing bookmarks — the two are mutually exclusive strategies. See [Merge PDFs](https://docs.chromiumly.dev/v6/pdf-engines/merge.md).

## split(options)

Split PDFs by page range or intervals.

```typescript theme={null}
PDFEngines.split({
  files: PathLikeOrReadStream[];
  options: Split;  // { mode: 'pages' | 'intervals', span: string, unify?, flatten? }
  pdfa?: PdfFormat;
  pdfUA?: boolean;
  metadata?: Metadata;
  userPassword?: string;
  ownerPassword?: string;
  allowPrinting?: boolean;
  allowCopying?: boolean;
  allowModifying?: boolean;
  allowAnnotating?: boolean;
  allowFillingForms?: boolean;
  allowAssembling?: boolean;
  watermark?: PdfEngineWatermark;
  stamp?: PdfEngineStamp;
  rotate?: PdfEngineRotate;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

`options.flatten` is nested here, unlike the top-level `flatten` field on Chromium/LibreOffice `convert()` — see the note in [Split PDFs](https://docs.chromiumly.dev/v6/pdf-engines/split.md). Import the `PdfEngineRotate` type from `chromiumly` when typing `rotate` options.

## rotate(options)

Rotate pages of one or more PDFs (dedicated [Gotenberg rotate route](https://gotenberg.dev/docs/8.x/manipulate-pdfs/rotate-pdfs)).

```typescript theme={null}
PDFEngines.rotate({
  files: PathLikeOrReadStream[];
  angle: 90 | 180 | 270;
  pages?: string;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## watermark(options)

Apply a watermark to one or more PDFs (dedicated route). `watermark.source` and `watermark.expression` are required.

```typescript theme={null}
PDFEngines.watermark({
  files: PathLikeOrReadStream[];
  watermark: PdfEngineWatermark;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## stamp(options)

Apply a stamp to one or more PDFs (dedicated route). `stamp.source` and `stamp.expression` are required.

```typescript theme={null}
PDFEngines.stamp({
  files: PathLikeOrReadStream[];
  stamp: PdfEngineStamp;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## flatten(files, webhook?, output?, downloadFrom?)

Flatten forms and annotations. Positional arguments, not an options object.

```typescript theme={null}
PDFEngines.flatten(
  files: PathLikeOrReadStream[],
  webhook?: WebhookOptions,
  output?: OutputOptions,   // { outputFilename?, trace? }
  downloadFrom?: DownloadFrom
): Promise<Buffer>
```

## readMetadata(options)

Read metadata from PDFs. Unlike `flatten`/`readBookmarks`, this takes a single options object, not positional arguments.

```typescript theme={null}
PDFEngines.readMetadata({
  files: PathLikeOrReadStream[];
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## writeMetadata(options)

Write metadata to PDFs.

```typescript theme={null}
PDFEngines.writeMetadata({
  files: PathLikeOrReadStream[];
  metadata: Metadata;  // key-value, e.g. Author, Title, Keywords
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## readBookmarks(files, webhook?, output?, downloadFrom?)

Read bookmarks from PDFs. Positional arguments, not an options object.

```typescript theme={null}
PDFEngines.readBookmarks(
  files: PathLikeOrReadStream[],
  webhook?: WebhookOptions,
  output?: OutputOptions,   // { outputFilename?, trace? }
  downloadFrom?: DownloadFrom
): Promise<Buffer>
```

## writeBookmarks(options)

Write bookmarks to PDFs.

```typescript theme={null}
PDFEngines.writeBookmarks({
  files: PathLikeOrReadStream[];
  bookmarks: Bookmark[] | Record<string, Bookmark[]>;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

## encrypt(options)

Encrypt PDFs with user and/or owner password (dedicated route). At least one of `options.userPassword` or `options.ownerPassword` is required; since Gotenberg 8.34.0, an owner-password-only request produces an owner-only PDF that opens without a password but still enforces permissions.

```typescript theme={null}
PDFEngines.encrypt({
  files: PathLikeOrReadStream[];
  options: {
    userPassword?: string;
    ownerPassword?: string;
    allowPrinting?: boolean;
    allowCopying?: boolean;
    allowModifying?: boolean;
    allowAnnotating?: boolean;
    allowFillingForms?: boolean;
    allowAssembling?: boolean;
  };
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

See [Encrypt PDFs](https://docs.chromiumly.dev/v6/pdf-engines/encrypt.md).

## embed(options)

Attach files to existing PDFs (dedicated route).

```typescript theme={null}
PDFEngines.embed({
  files: PathLikeOrReadStream[];   // PDFs to modify
  embeds: PathLikeOrReadStream[];  // files to attach
  embedsMetadata?: EmbedsMetadata;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

See [Embed files](https://docs.chromiumly.dev/v6/pdf-engines/embed.md).

## facturX(options)

Turn existing PDFs into Factur-X / ZUGFeRD e-invoices (dedicated route): embeds the CII invoice XML under the canonical `factur-x.xml` name and converts the PDF to PDF/A-3.

```typescript theme={null}
PDFEngines.facturX({
  files: PathLikeOrReadStream[];
  facturx: FacturXOptions;
  downloadFrom?: DownloadFrom;
  webhook?: WebhookOptions;
  outputFilename?: string;
  trace?: string;
}): Promise<Buffer>
```

See [Factur-X / ZUGFeRD](https://docs.chromiumly.dev/v6/pdf-engines/factur-x.md).

## generate(filename, buffer)

Convenience: write a buffer to `__generated__/<filename>` in the current working directory.

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

Creates `__generated__` if it does not exist.


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