I create a lot of booklets. Usually, this is because it’s a great way for me to put together some files and take them with me. I can slip them in a briefcase or backpack, and pull them out to read whenever I have a few spare moments.

I recently had a situation where I had some man files about printing from the command line. (You wouldn’t necessarily think that this is a handy thing to be able to do, but it is. I’ll talk more about that in a later post, probably.)

Anyway, I exported the man files to half-page pdfs (I describe the process in greater detail here.) I exported the man documents for the following commands:

  • lp
  • lpoptions
  • lpq
  • lpr
  • lprm
  • lpstat
  • cancel

I then combined them into a single pdf using pdftk:

pdftk lp.pdf lpoptions.pdf lpq.pdf lpr.pdf lprm.pdf lpstat.pdf cancel.pdf cat output lpman.pdf

I now had a nice 18-page pdf that I could run through PDF Booklet

The problem I ran into was that each of those smaller pdf files were already numbered. So I ended up with a booklet with page numbering like this: 1 2 3 4 1 2 1 2 1 2 3 1 2 1 2 3 1 2. What I really wanted was page numbers that ran like this: 1 2 3 4 5 6 7 8 9 10…well, you get the idea.

As it turns out, this is not an easy thing to do. Sure, there are lots of commercial products available that are very expensive and more than I want to spend for such a simple project. So I spent some time searching. 

I eventually found an answer here, courtesy of Chloé-Agathe Azencott. The answer is to create a separate pdf document with the same size and number of pages as your document, and then use pdftk to combine them.

Creating a pdf of nothing but page numbers is simple enough for LaTeX, and you can see an example on Professor Azencott’s blog post above. For what it’s worth, I whipped up my own version based on hers which has a few more options. I’ve added it to my git instance, where you can download a copy and play around with it.

Once you have your two documents, the command for combining them via pdftk is simple:

pdftk blank.pdf multistamp numbers.pdf cat output numbered_doc.pdf

This is as good a way as any to add page numbers, and probably the fastest, as well. A special thanks to Professor Azencott. (Also be sure to read her list of good work practices.)