Hack 53 Add PDF Encryption Actions to Windows Context Menus

figs/moderate.gif figs/hack53.gif

Apply or remove encryption from a given PDF with a quick right-click.

[Hack #52] discussed how to apply or remove PDF encryption with pdftk [Hack #79] . Let's streamline these security operations by adding handy Encrypt and Decrypt items to the PDF context menu. The encryption example simply applies a user password to the selected PDF, so nobody can open it without the password. The decryption example removes all (Standard) security, upon success.

5.4.1 Add the Encrypt PDF Context Menu Item

Windows XP and Windows 2000:

  1. In the Windows File Explorer menu, select 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 Encrypt.

  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 C:\windows\system32\pdftk.exe "%1" output "%1.encrypted.pdf" 
    encrypt_128bits user_pw PROMPT

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

5.4.2 Add the Decrypt PDF Context Menu Item

Follow the preceding procedure, except name the action Decrypt and replace the cmd.exe arguments in step 4 with:


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

output "%1.decrypted.pdf"

5.4.3 Using Encrypt or Decrypt

Right-click your PDF of interest and select Encrypt or Decrypt from the context menu. A command prompt will open and ask for the password. Upon success, the command prompt will close. pdftk will create a new PDF file with a name based on the original PDF's filename. If pdftk has trouble executing your request, the command prompt will remain open with a message. Press Enter to close this message.

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