Hein (fub) wrote,


One of the coolest features of OpenOffice.org Writer is the so-called 'Brochure' printing option. That will put two pages on each side of a sheet of paper, in the correct order to make a signature: if you make a stack of the sheets and fold them in half, you have a 'booklet' that is fit for brochure binding. However, that printing option makes only a single signature -- so it works for documents upto 20 pages. That's five sheets, and that's about the maximum size of signatures with 80 grams printing paper. And most documents are distributed as PDF anyway...
So, suppose you have a PDF (either something you created yourself from your own document, or for instance an RPG you bought from RPGNow or a PDF with all the MERP modules you torrented from somewhere) and you want to create a book from it -- what do you do?

First, you will need to install three packages: ghostscript, psutils and poppler-utils. Then, paste this text into a script file somewhere in your path:

if [ $# -ne 3 ]; then
  echo "Usage: $0 inputfile sheets_per_signature outputfile"
  exit 0
# Strip DRM
echo "Stripping DRM..."
gs -q -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=/tmp/stripped.pdf $1 -c '.setpdfwrite'

# Convert to PS
echo "Converting to Postscript..."
pdftops /tmp/stripped.pdf /tmp/stripped.ps
rm /tmp/stripped.pdf

# Convert to booklet
echo "Converting to booklet..."
psbook -q -s$2 /tmp/stripped.ps /tmp/signatured.ps
rm /tmp/stripped.ps

# Two pages per sheet
echo "Two pages per sheet..."
psnup -q -l -pa4 -2 /tmp/signatured.ps /tmp/booked.ps
rm /tmp/signatured.ps

# Convert to PDF
echo "Converting to PDF..."
gs -q -dCompatibilityLevel=1.4 -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=$3 /tmp/booked.ps -c '.setpdfwrite'
rm /tmp/booked.ps

echo "Done!"

What each step does is written in the comments. The crux is the call to psbook, which divides the file into signatures. It's a neat program, but it's pretty dumb: if you ask for 20 pages per signature (5 sheets), you will get 20 pages, even if the document is only 16 pages! So you're better off choosing your signature size carefully. I might write an additional script that calculates the size of the last signature, but that's something for the future.
It works well, and it works better than doing it all manually through Evince and the PDF printer driver.
Tags: linux, tools

  • Troubles restarting

    As ‘the troubles’ seem to be restarting (which anyone could have foreseen), I am thinking about my visit to Northern Ireland in 2015. I…

  • Things that happened this week

    A power interruption. We had gotten a letter from the company that manages the power lines that they’d be working on the infrastructure on…

  • Karen Sparck Jones, one of the greats

    If you’re on Twitter, you should follow the account OnThisDayShe, which highlights an (often overlooked) woman who helped shape our world.…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded