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

# Attachments

> Embed, list, remove, and extract files embedded in PDFs.

## Attach

`attach` embeds a file in the PDF, one file per stage.

| Option | Type | Description |
| - | - | - |
| `file` | [`StageFile`](https://docs.chromiumly.dev/stages#files-a-stage-needs) | The file to embed (required) |
| `name` | `string` | The name the PDF lists it under (default: the file's name) |
| `mimeType` | `string` | The file's MIME type (default: from the name) |
| `relationship` | `string` | `"Source"`, `"Data"`, `"Alternative"`, `"Supplement"` or `"Unspecified"`. Makes the file a PDF/A-3 associated file |

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

const withData = await PDF.attach({
  files: ["path/to/report.pdf"],
  file: "path/to/data.csv",
  mimeType: "text/csv",
  relationship: "Data",
});
```

Several files take several stages:

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

const buffer = await new HtmlConverter().convert({
  html: "path/to/index.html",
  stages: [
    { op: "attach", file: "path/to/data.csv", relationship: "Data" },
    { op: "attach", file: "path/to/source.xlsx", relationship: "Source" },
  ],
});
```

For a Factur-X invoice, don't attach the XML yourself: [`remediate`](https://docs.chromiumly.dev/pdf/conformance#factur-x) with `profile: "Factur-X"` embeds it as the standard requires.

## List

`PDF.attachments()` lists the embedded files, with their media type and relationship when the PDF states them:

```typescript theme={null}
const attachments = await PDF.attachments({ files: ["path/to/invoice.pdf"] });
// { "invoice.pdf": [{ name: "factur-x.xml", mimeType: "text/xml", relationship: "Data" }] }
```

## Detach

`detach` removes an embedded file by the `name` the PDF lists it under. A name it doesn't list is refused with a 400.

```typescript theme={null}
const cleaned = await PDF.detach({ files: ["path/to/invoice.pdf"], name: "factur-x.xml" });
```

## Extract

`PDF.extractAttachments()` returns the embedded files: all of them, or one by `name`. As the last stage of a list, `extract-attachments` returns them in a ZIP next to the PDF.

```typescript theme={null}
const files = await PDF.extractAttachments({ files: ["path/to/invoice.pdf"] });
```

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


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