Home
A PDF can carry other files: attached to the whole document (listed in the Bookmarks sidebar) or to a spot on a page (a paperclip or pushpin icon). Open or save them from SumatraPDF, or save them all from the command line.
Right-click the attachment and choose Save Attachment. At a glance:
  • Files attached to the document: listed at the end of the Bookmarks sidebar (F12); right-click → Save Attachment… or Open Attachment.
  • File attachment on a page: click the icon to open the file; right-click → Save Attachment.
  • Command line: sumatrapdf-tool extract file.pdf saves every attached file (plus images and fonts).
  • Command line, original names: a short run script, see below.

Save a file attached to the document #

  1. Open the PDF and show the sidebar: F12, or View → Show Bookmarks. Attached files are listed after the table of contents, by file name. Hover one to see Attachment: ....
  2. Right-click the file name and choose:
    • Save Attachment… (CmdSaveAttachment): a save dialog opens with the attachment’s name in the PDF’s folder.
    • Open Attachment (CmdOpenAttachment): opens it in a new tab. Shown only for .pdf attachments.
Clicking an attachment in the sidebar does nothing; use the right-click menu.
Note: the sidebar menu can also show Save Embedded File… (CmdSaveEmbeddedFile) and Open Embedded PDF (CmdOpenEmbeddedPDF), for bookmark entries that link to an embedded file. They work the same way.

Save a file attached to a page #

A file attachment annotation shows as an icon on the page, for example a paperclip or a pushpin.
  • Open it: click the icon. A file SumatraPDF can open (a PDF, an image, …) opens in a new tab (ver 3.7+). For other files, save them.
  • Save it: right-click the icon → Save Attachment, then pick where to save. The name defaults to the attachment’s name in the PDF’s folder.
  • In Edit PDF mode: click the annotation; its property row has Save Attachment (see Editing annotations).
To attach a file yourself, use the File Attachment annotation (see Editing annotations).
None of these commands are in the Command Palette: they act on the attachment you right-click.

Save attachments from the command line #

Available in pre-release 3.7

Save everything #

sumatrapdf-tool extract report.pdf
extracting file-0017.csv (data.csv)
extracting file-0019.txt (notes.txt)
  • Files attached to the document and to pages are both saved, as file-<object number>.<extension>. The original name is printed in parentheses.
  • Files go to the current folder, not the PDF’s folder.
  • extract also saves every image and font in the PDF. To save only one file, give its object number: sumatrapdf-tool extract report.pdf 17.
To find the object numbers of document attachments without extracting anything:
sumatrapdf-tool show report.pdf trailer/Root/Names/EmbeddedFiles/Names
[ (data.csv) 17 0 R ]
More options: sumatrapdf-tool extract.

Save attachments with their names #

This script saves document attachments and page attachments to the current folder, under their own names. Save it as save-attachments.js:
// usage: sumatrapdf-tool run save-attachments.js file.pdf
var doc = Document.openDocument(scriptArgs[0]);
function save(name, fs) {
    var buf = doc.getEmbeddedFileContents(fs);
    if (buf) {
        buf.save(name);
        print("saved " + name);
    }
}
var files = doc.getEmbeddedFiles();
for (var name in files) {
    save(name, files[name]);
}
for (var i = 0; i < doc.countPages(); i++) {
    doc.loadPage(i).getAnnotations().forEach(function (a) {
        if (a.getType() == "FileAttachment" && a.hasFilespec()) {
            var fs = a.getFilespec();
            save(doc.getFilespecParams(fs).filename, fs);
        }
    });
}
sumatrapdf-tool run save-attachments.js report.pdf
saved data.csv
saved notes.txt
A file with the same name is overwritten. Use SumatraPDF.exe instead of sumatrapdf-tool if you only have SumatraPDF installed (see Tools).

Tips #

  • Use sumatrapdf-tool extract in an empty folder: it can write many image and font files.
  • Use Batch process PDFs to run the script over a folder of PDFs.
  • If nothing is listed, the PDF has no attached files; a link to an outside file is not an attachment.

See also #