PDF Attachments Manager
Operator: Abdulla Al Fahad. How tools are built and checked
Hybrid e-invoices such as Factur-X and ZUGFeRD carry their machine-readable XML inside the PDF as an attached file, and some reports carry the spreadsheet behind their charts. Most viewers show attachments in a side panel you have to know to open, and show paperclip notes pinned to a page separately, so it is easy to forward a PDF without knowing what else rides along.
This tool lists everything embedded, from both places, with name, description, size, type and modified date. You can save one file, save a ticked selection as a ZIP, mark entries for removal, or add files of your own, and the result is written as a copy.
Removal deletes the embedded streams outright rather than hiding them: removing all three attachments in the example below took the PDF from about 2.5 KB to about 1.6 KB.
Key features
- Lists attachments-panel files and page paperclip notes together
- Saves one file, a ticked selection or all of them as a ZIP
- Removes attachments, including page notes, and deletes their data from the saved copy
- Adds files with an optional description, up to 100 MB each
Where a PDF keeps embedded files
A PDF keeps embedded files in two places. At document level there is the EmbeddedFiles name tree under /Names in the catalog, which is what an attachments panel shows. At page level there are FileAttachment annotations, the paperclip and pushpin icons. Both point at a file specification dictionary, /Type /Filespec, with the file name in /UF (Unicode) or /F, an optional /Desc, and /EF holding the embedded file stream.
The stream carries /Subtype, the MIME type written with # escapes such as application#2Fpdf, and /Params with /Size (the unpacked size), /ModDate and sometimes /CheckSum. The stored size shown is the packed length. A file specification that names a file but has no /EF points at something outside the PDF; it is listed with a note and cannot be extracted. A /Collection entry marks a PDF portfolio, which the tool mentions because its cover page is only a placeholder.
An attachment is refused when its declared unpacked size is over 200 MB. A Flate stream is inflated with a running byte count and stopped past 200 MB, so one that misstates its size cannot exhaust memory, and a ZIP may hold 400 MB in all. Every Flate stage of a filter chain goes through that cap, PNG predictors are undone afterwards, ASCII hex and ASCII85 are decoded, and any other filter, such as LZW or RunLength, is refused.
File names are made safe before they go into a ZIP or a download: only the last path segment is kept, so ../evil/bin.dat becomes bin.dat, characters illegal on Windows or macOS become spaces, reserved names such as CON get an underscore, and repeated names get " (2)" before the extension.
How it works
The file is opened with the page-tools loader, the name tree and every page's annotation list are walked, and each file specification is read into one row. Saving removes the ticked entries, rewrites the name tree as one flat sorted list so every viewer reads it, deletes the removed specification and stream objects, cleans their entries from the catalog's /AF list used by PDF/A-3, and embeds new files compressed, with their type, description and the current time as modified date.
Common use cases
- A Factur-X invoice from a supplier: save factur-x.xml from the panel to feed an accounting import, while the PDF stays untouched.
- A 4 MB board pack with a forgotten spreadsheet of salary bands attached: tick Remove, save, and the copy that goes out no longer carries it.
How to use this tool
- Drop the PDF to see what is inside it.
- Use Save beside one row, or tick rows and choose ZIP of ticked or ZIP of all.
- To edit, tick Remove on rows or add files on the left, then press Save changed PDF.
Example
A 2-page PDF with two attachments and one page-2 note
Attachments panel: data.csv (text/csv, 4,000 bytes unpacked, 37 stored, described "Sample ünï") and ../evil/bin.dat (application/octet-stream, 5 bytes)
Page 2 paperclip: note.txt (9 bytes, "a pinned note")What the tool does with it
Save all as a ZIP: bin.dat, data.csv and note.txt (the ../evil/ folder part of the first name is dropped)
Removing bin.dat and the page note and adding new.txt leaves data.csv and new.txt in the panel
Removing all three leaves no attachments and shrinks the file from about 2.5 KB to about 1.6 KBCommon pitfalls
Removing the XML from a Factur-X or ZUGFeRD invoice leaves a plain PDF, which a receiving system that expects the XML will reject.
Saving drops printing and copying restrictions and says so, and a digitally signed file stops validating after any edit.
An attached PDF is extracted as a file; attachments inside it are not unpacked on the way, so save it and open the saved file.
Linked files and entries listed under /AF without an embedded stream have nothing to extract.
- The Relationship column shows /AFRelationship, used by PDF/A-3 files, with values such as Source, Data or Alternative. It is blank for ordinary attachments.
- Ticking Remove on a paperclip note deletes the whole annotation, icon included, since an icon with no file behind it would point nowhere.
Common errors and how to fix them
- "Points to a file outside the PDF"
- The entry links to a file on disk instead of holding it, so there are no bytes in the PDF to extract. It can still be removed.
- "Unpacks to more than 200 MB"
- The attachment is larger than the tool will unpack in a browser tab. Extract it with a desktop PDF program instead.
- "Uses the LZWDecode compression, which this page does not unpack"
- Only Flate, ASCII hex and ASCII85 streams are unpacked here. Extract a file that uses another filter, such as LZW or RunLength, with a desktop PDF program.
Best practices
- Extract before you remove: the saved copy no longer holds the files, and the original is the only place they remain.
What changes in the saved copy
Only the attachment structures are touched, and the pages are written as they were.
- The EmbeddedFiles name tree is rewritten as a single sorted list, replacing any nested /Kids tree.
- Removed file specifications, streams and page annotations are deleted, and their entries leave the /AF list.
- Added files are compressed and stored with their MIME type, description and a modified time set at saving.
Hybrid invoices
Factur-X, which Germany calls ZUGFeRD from its version 2 on, is one readable invoice page with a structured XML file embedded in the same PDF, so people read one and accounting software reads the other. Listing the attachments here is a quick way to confirm that the XML is really present before a file is sent on.
Frequently asked questions
Can it open a PDF that is attached inside another PDF?
It saves the attached PDF as a file. Open that saved file in the tool to see anything attached to it, since attachments of attachments are not unpacked recursively.