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, or right-click → Save Attachment to save it.
  • 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, so use the right-click menu.
Files attached to a PDF, listed after the bookmarks, and the right-click menu with Save Attachment...
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).
A file attachment icon on a page and its right-click menu
To attach a file yourself, use the File Attachment annotation (see Editing annotations).
The attachment commands are not in the Command Palette, because 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 #

The following script saves document attachments and page attachments under their own names, to the folder given as the second argument or to the current folder. Save it as save-attachments.js:
// usage: sumatrapdf-tool run save-attachments.js file.pdf [folder]
// Info: Save attachments under their own names.
// Arg: <INPUT> : PDF with attachments
// Arg: <DIR> : Output folder (empty = current folder)
var doc = Document.openDocument(scriptArgs[0]);
var dir = scriptArgs[1] || "";
function save(name, fs) {
    var buf = doc.getEmbeddedFileContents(fs);
    if (buf) {
        var path = dir ? dir + "/" + name : name;
        buf.save(path);
        print("saved " + path);
    }
}
// getEmbeddedFiles() throws when the PDF has no document attachments
var files = doc.getTrailer().get("Root", "Names", "EmbeddedFiles") ? 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, because 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 #