Hack 79 Tool Up with pdftk

figs/moderate.gif figs/hack79.gif

Take control of your PDF with pdftk.

If PDF is electronic paper, pdftk is an electronic staple-remover, hole punch, binder, secret-decoder ring, and X-ray glasses. pdftk is a simple, free tool for doing everyday things with PDF documents. It can:

  • Split and merge PDF pages [Hack #51]

  • Decrypt and encrypt PDF documents [Hack #52]

  • Burst a PDF document into single pages [Hack #71]

  • Uncompress and recompress page streams [Hack #80]

The pdftk web site (http://www.AccessPDF.com/pdftk/) has links to software downloads and instructions for installation and usage. pdftk currently runs on Windows, Linux, Solaris, FreeBSD, and Mac OS X. Some users can download precompiled binaries, while others must download the source code and build pdftk using gcc, gcj, and libgcj (as described on the web site). pdftk is free software.

On Windows, download pdftk_1.0.exe.zip to a convenient directory. Unzip with your favorite archiving tool, and move the resulting pdftk.exe program to a directory in your PATH, such as C:\windows\system32\ or C:\winnt\system32\. Test it by opening a command-line DOS prompt and typing pdftk --help. It should respond with pdftk version information and usage instructions.

Additional free PDF tools include mbtPDFasm (http://thierry.schmit.free.fr/dev/mbtPdfAsm/enMbtPdfAsm2.html) and the Multivalent Tools (http://multivalent.sourceforge.net/Tools/index.html). Related commercial tools include pdfmeld (http://www.fytek.com/).


6.7.1 Handy Command Line for Windows

Command prompts aren't well suited for quickly navigating large, complex filesystems. Let's configure the Windows File Explorer to open a command prompt in the working directory we select. This will make it easier to use pdftk in a specific directory.

Be sure to add this new action to the Folder file type, not the File Folder file type.


Windows XP and Windows 2000:

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

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

  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\, or C:\winnt\system32\.

  4. Add these arguments after cmd.exe like so:

    C:\windows\system32\cmd.exe /K cd "%1"

  5. Click OK, OK, OK and you are done.

Windows 98:

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

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

  3. Give the action an application to open by clicking the Browse . . . button and selecting command.com, which lives somewhere such as C:\windows\.

  4. Add these arguments after command.com like so:

    C:\windows\command.com /K cd "%1"

  5. Click OK, OK, OK and you are done.

Test your configuration by right-clicking a folder in the File Explorer. The context menu should list your new Command action, as shown in Figure 6-7. Choose this action and a command prompt will appear with its working directory set to the folder you selected. Olé!

Figure 6-7. Opening a command prompt right where you need it
figs/pdfh_0607.gif


Instead of typing long filenames into the command prompt, select a file in the File Explorer and drag it over the command-line window. When you drop it, its full filename will appear at the cursor.