# `delete_attachments` Delete file attachments based on criteria ## Usage > pdftl `` `delete_attachments` `[[spec](params)...]` `output` `` ## Details The `delete_attachments` operation removes attached files from the PDF. By default, it will permanently delete all attachments from the document, but it can be heavily customized to target specific files based on where they are located, what they are named, how large they are, or their relationship. **Global, Page-Based, or Document-Level:** - **Global (Default):** If you omit the selector or use `-`, the operation will delete matching attachments everywhere (both document-level and page-level). - **Document-Level (`doc`):** If you use the selector `doc`, it will only look at attachments that exist purely in the document's global attachment panel and are *not* visually attached to any specific page. - **Page-Based (`1-5`, `odd`, etc.):** If you provide a specific page range, it will only delete attachments that are linked as clickable annotations on those pages. The syntax is `[selector](Key=Value, ...)`, where: - `selector` is optional (`1-5`, `doc`, `-`). Omitting it acts globally. - `Key=Value` pairs define the filter criteria an attachment must meet to be deleted. ### Filter Parameters | Parameter | Description | Example | | :--- | :--- | :--- | | `name` | Match the attachment's full filename (case insensitive). | `name=draft.txt` | | `namehas` | Match a substring of the full filename (case insensitive). | `namehas=draft` | | `ext` | File extension match (with or without the dot). | `ext=csv`, `ext=.jpg` | | `minbytes` | Min file size. Supports `k`, `m`, `g` suffixes. | `500k`, `2m` | | `maxbytes` | Max file size. Supports `k`, `m`, `g` suffixes. | `10000`, `1.5m` | | `relation` | Exact match against relationship type (e.g. `Source`, `Data`). | `relation=Data` | *Note: If multiple parameters are provided, an attachment must meet ALL criteria to be deleted.* ## Examples > Globally delete all attachments from the PDF. ``` pdftl in.pdf delete_attachments output out.pdf ``` > Globally delete all attachments that are PDF files. ``` pdftl in.pdf delete_attachments '(ext=pdf)' output out.pdf ``` > Delete document-level attachments (not on specific pages) that are larger than 1MB. ``` pdftl in.pdf delete_attachments 'doc(minbytes=1m)' output out.pdf ``` > On pages 1 through 5, delete ZIP attachments designated as 'Source'. ``` pdftl in.pdf delete_attachments '1-5(relation=Source,ext=zip)' output out.pdf ``` **Tags**: in_place, attachments, optimization, delete *Source: pdftl.operations.delete_attachments* *Read online: [https://pdftl.readthedocs.io/en/latest/operations/delete_attachments.html](https://pdftl.readthedocs.io/en/latest/operations/delete_attachments.html)* *Type: Operation*