Log in

No account? Create an account
Jul. 7th, 2010 @ 09:14 pm PDFbook
Current Location: Nijmegen
Current Mood: accomplishedaccomplished
Tags: ,
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.
About this Entry
[User Picture Icon]
Date:July 8th, 2010 10:20 pm (UTC)
(Permanent Link)
I'll be honest, I didn't understand a word of that besides RPG and PDF. So I'll just pretend that was the subject of this post. (why yes, my hair feels quite pointy right now and the need to say vague buzzwords is growing, how nice of you to notice..)

Hey, Speaking about RPG's in pdf forms do you know a rolemaster 2 PDF somewhere so I can read up a bit? I tried finding one myself but failed horribly and I want to at least try to know and understand a little bit more of the system so I wont be a total newby, I mean it's going to be difficult enough for you as it is without me asking every second throw what what is...
(Reply) (Thread)
[User Picture Icon]
Date:July 10th, 2010 03:49 pm (UTC)
(Permanent Link)
Heh. Let's just say that this script makes it easier for me to generate contents for my bookbinding hobby from PDFs.

Iron Crown Enterprises has risen from the grave (after being forced out of business by Tolkien Enterprises when the Lord of the Rings movies were set to come out), and they still, in fact, sell RM2 -- but now they call it 'Rolemaster Classic'. Look here for info -- they do sell PDFs of the basic books. They also sell 'Rolemaster Express', which is a slightly condensed and less 'rich' version of Rolemaster. Look for the differences here.
That being said, there aren't that many rules that you need to know as a player. D&D is much more 'technical' in that respect.
(Reply) (Parent) (Thread)