Script for converting a pdf to book format: an update

With reference to [1], the script posted by dokan fails via a Bash syntax error because my version of pdftk 1.41 has multiple lines matching to "Num", which are stored in the TOTAL variable. If we modify the first non-ignored line of the script from

# Original
TOTAL=$( pdftk "$1" dump_data output | grep -i Num | cut -d \  -f2 )

to

# New
TOTAL=$( pdftk "$1" dump_data output | grep -i Number | cut -d \  -f2 )

the script works as expected.

However, its output isn't perfect. In inputting an eighteen page pdf and printing the output, I see that the middle two pages of the document (printed last) are not on the front-and-back of the last sheet, but are instead side-by-side on the same side of the sheet. Therefore, upon converting it to booklet form, instead of having an extra blank "sheet" (half-sheet) at the end of the document, I have two empty pages in the middle of it.

If this (minor but important) issue were fixed, this would be equivalent to printing "Booklet mode" from Acrobat Reader.

Thanks to dokan.

[1] Script for converting a pdf to book format

Well I feel sheepish. PDFjam ships with pdfbook, which solves exactly this problem and better. Yay!

As I can't post URLs, search for:

PDFjam is a small collection of shell scripts which provide a simple interface to much of the functionality of the excellent pdfpages package (by Andreas Matthias) for pdfLaTeX.
...
pdfbook which arranges pages into 2-up "signatures" (like psbook does for PostScript files), suitable for binding into a book. (Many people have suggested that this would be useful - I hope it is!)