32leaves.net

Yet another PDF utility

Today I had the task to write join some PDF files together and creating an outline entry for each file in the new document. As it turned out that was not such a trivial task as it may sound. Merging PDF files is pretty straight forward. Pretty much every tool that has something with PDF in its name is capable of doing so. Unfortunately that’s not the case when it comes to the outline stuff. Even after hours of googling for a solution I didn’t find one. So there was only one way left: write it myself. And so I did (but rather quick and dirty) … the outcome is a neat little helper based on PDFBox. See the help below to get an idea of what it’s capable of:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
usage: pdfutils <tool> <args>
    Available tools: merge help title author info dropoutline addoutline
type "pdfutils help <tool>" to get some help for <tool>

usage: pdfutils addoutline
 -B <page=title>   Add outline entry for page and title. The page can be
                   in the format "10.20" adding the bookmark to page 20 as
                   a sublevel to the bookmark for page 10 which must be
                   given beforehand. As of now it is not possible to add
                   subnodes to already existing bookmarks.
 -f <file>         The input file

usage: pdfutils author
 -f <file>    The file to modify
 -v <value>   The value to set

usage: pdfutils dropoutline
 -f <file>   The input file

usage: pdfutils info
 -f <file>   The input file

usage: pdfutils merge
 -i,--input          A whitespace seperated list of input files
 -n,--no-outline     If set no outline is computed - so the outline of the
                     first source document is used
 -o,--output <arg>   The output file

usage: pdfutils title
 -f <file>    The file to modify
 -v <value>   The value to set

So in case you wanted to merge a bunch of PDF files in the current directory and have a neat outline afterwards, you could issue this command:

1
java -jar pdfutils_0.1.1.jar merge -o ../merged.pdf -i `ls *.pdf`
You can download the binary (including all required libraries, so it’s ready to go) or check out the sources. The username and password for websvn is guest and the code is published under the terms of Apache License 2.0.
Note: Some software readers seam not to care about the outline generated by PDFBox … but e.g. the Sony PRS505 does.

One Response to “Yet another PDF utility”

  1. Bernhard says:

    What about Drag’n Drop in Preview …

Leave a Reply

Fork me on GitHub