Hack 56 Add PDF Attachment Actions to Windows Context Menus

figs/moderate.gif figs/hack56.gif

Pack or unpack PDF attachments from the Windows File Explorer with a quick right-click.

It's best to perform simple tasks in a simple manner, especially when you must perform them often. Wire pdftk [Hack #79] into Windows Explorer so that you can pack or unpack attachments using PDF's right-click context menu.

5.7.1 Create the Attach File Context Menu Item

In Windows XP and Windows 2000:

  1. In the Windows File Explorer menu, open Tools Folder Options . . . and click the File Types tab. Select the PDF file type and click the Advanced button.

  2. Click the New . . . button and a New Action dialog appears. Give the new action the name Attach File.

  3. Give the action an application to open by clicking the Browse . . . button and selecting cmd.exe, which lives somewhere such as C:\windows\system32\ (Windows XP) or C:\winnt\system32\ (Windows 2000).

  4. Add these arguments after cmd.exe, changing the path to suit, like so:

    C:\windows\system32\cmd.exe
    
    /C C:\windows\system32\pdftk.exe "%1" attach_file PROMPT output PROMPT

  5. Click OK, OK, OK and you should be done with the configuration.

5.7.2 Create the Unpack Attachments Context Menu Item

Follow the previous procedure, except name the action Unpack Attachments and replace the cmd.exe arguments in step 4 with:

/C C:\windows\system32\pdftk.exe "%1" unpack_files

5.7.3 Using Attach File or Unpack Attachments

Right-click your PDF of interest and select Attach File or Unpack Attachments from the context menu. A command prompt will open and ask for additional information. Upon success, the command prompt will close. If pdftk has trouble executing your request, the command prompt will remain open with a message. Press Enter to close this message.

Use drag-and-drop to quickly enter the filenames for the files you want to attach. Select a file in Explorer, drag it over to the command-line window, and drop it. Its full filename will appear at the cursor. This works for only one file at a time.


If you invoke one of these commands on a selection of multiple PDFs, you will get one command prompt for each PDF.