Side project: booklet printing in Ubuntu made easy

Booklets consist of sheets of paper folded a couple times to form a book-like version of a document. For example, you could create an A5 booklet by printing a document on A4 paper, 2 sheets per page, with the sheets arranged in such a way that the resulting pages of A4 paper can be folded in half to form an A5 booklet.

I prefer booklet printing of documents over plain duplex printing because it wastes a lot less paper, and results in a more comfortable size to carry around said printed documents.

Unfortunately, Ubuntu doesn't have a booklet printing option unlike MacOSX (so I've been told). This means that printing documents as booklets involves saving the document and running it through a couple of commandline tools before sending it to the printer. Because these steps are too elaborate, I knew my natural laziness would kick in and I'd stop printing booklets if there was no automated solution.

I decided to create a CUPS backend to print booklets. Once installed, the booklet printer that uses this backend is available to any program that uses CUPS for printing. On Ubuntu, that means every program :) When the booklet backend receives the PDF document, it converts it into booklet form and forwards it to any printer you want.

The backend script requires a couple tools that need to be installed first:

apt-get install impose+ psutils
The code for the backend then, is very simple:

if [ $# -eq 0 ]; then
echo "direct booklet \"Unknown\" \"Print a document in booklet form\""
exit 0


cat $6 | fixtd -tumble | psbook | /usr/bin/pstops "2:0L@.7(21cm,0)+1L@.7(21cm,14.85cm)" | lpr -T "$title" -U "$user" -P "$out"

exit 0

To use this backend on Ubuntu, download the code into /usr/lib/cups/backend/booklet and set it executable. Then, goto http://localhost:631 and login to your CUPS interface. Create a new printer of the booklet type. Next, type in the booklet printer URI: booklet:/MyPrinter (mind the single slash) will install a booklet printer that forwards the processed document to the "MyPrinter" printer. Make sure it's a duplex printer. Give the printer a name (e.g. "booklet") and indicate that it is a Generic Postscript Printer. Finally, set some default options. In my case, I want A4 paper and duplex along the long edge (standard).

The printer should now be installed and ready for use