delete_attachments
Delete file attachments based on criteria
Usage
pdftl
<input>delete_attachments[[spec](params)...]output<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 selectordoc, 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:
selectoris optional (1-5,doc,-). Omitting it acts globally.Key=Valuepairs define the filter criteria an attachment must meet to be deleted.
Filter Parameters
Parameter |
Description |
Example |
|---|---|---|
|
Match the attachment’s full filename (case insensitive). |
|
|
Match a substring of the full filename (case insensitive). |
|
|
File extension match (with or without the dot). |
|
|
Min file size. Supports |
|
|
Max file size. Supports |
|
|
Exact match against relationship type (e.g. |
|
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
Type: Operation