Thursday, May 14, 2009

Wikipedia to Pamphlet using Hardy

I have been perpetually annoyed by having to print things out on full size pieces of paper instead of in smaller, book-sized, pamphlet size for some time, and I finally learned how to do it. Here is a brief tutorial that assumes the following tools:
* Open Office
* Psutils (contains pstops)
* Ps2pdf

This text was invaluable.


I did this on Hardy Heron.

First I copied a wikipedia article on Minoan Civilization to have something to read. I pasted it into an Open Office Document with the following margins (in inches): L 1.50, R 1.40, Top 0.79, B 0.79. I pasted it as plain text and fussed with it a little (removed the alt text), but mostly I left it alone. I then opened the Print... dialog box and used the Print to file option. This creates a postscript file that can be manipulated by psutils.

I used pstops for something called "imposition", which just means moving the logical pages around so you can fold it into a booklet. Here is the command I used to create the imposition I went with:

$pstops \
"4:1L@0.8(8.15in,0)+2L@0.8(8.15in,5.39in),3L@0.8(8.15in,0)+0L@0.8(8.15in,5.39in)" \
minoa.ps minoaImp.ps


Breaking it down:
4 means "cluster in logical pages of 4"
: separates
1 means "take the 2nd logical page (0-indexing makes it 1)"
L means "rotate it to the left (it pivots on the lower left corner)"
@ separates
0.8 means "scale it down to .8 of its normal size"
( separates
8.15in means "move it 8.15 inches back towards the physical page"
, separates
0 means "don't move it up or down"
) separates
+ means "start to work on a new logical page but stay on the same physical page"
(same deal for the third page)
, means "start to work on the next physical page

I kept fussing with the scale and the amount to move each of the pages both up and to the right until I was happy with it. The manipulation is very fast, so the iterative "move it a bit and look at it" did not take much time and was much more effective for me than measuring would have been.

After that, I ran
$ps2pdf monoaImp.ps

which creates a pdf named "monoaImp.pdf". This command takes much more time than pstops.

The printer I use at work prints duplex by flipping on the short side. If you want to flip on the long side, you will need to rotate the logical pages on the second physical page to the right and add a "-dAutoRotatePages=/None" option to the ps2pdf command. I leave this option in my script, as it does not seem to do any harm and I don't want to bother looking it up again.

After printing a few articles, I started working on pdfs. You start by converting it to ps with
$pdftops Remix.pdf

My first pdf was a 324-page book which was formatted at 7"x9.75". The ps2pdf kept outputting 8.5"x11" and it would never line up correctly. The trick I ended up using was

$pstops "2:0,1" Remix.ps Remix2.ps

This command should not have done anything (essentially it says, "work on two pages, put the first logical page on a sheet of paper and put the second logical page on the next one"), but as a side effect it converted it to 8.5"x11" (as an OO programmer, I love side effects!). Of course, the page content wasn't in the center any more, but as I was scaling and moving the content anyway, it didn't matter.

I found a second gotcha working with an A4 pdf. In this case, instead of forcing it down to 8.5"x11", I just converted the pre-imposed ps to imposed pdf by running a shell script, then kept fussing with the parameters until I was happy with the final output rather than the intermediate one.

Of course, I don't do any of the iterative work on the command line. Here is the full code of the script I use:

#!/bin/bash
rm RemixImp.*
pstops "4:1L@0.8(8.15in,0)+2L@0.8(8.15in,5.39in),3L@0.8(8.15in,0)+0L@0.8(8.15in,5.39in)" Remix.ps RemixImp.ps
ps2pdf -dAutoRotatePages=/None RemixImp.ps RemixImp.pdf


The "rm" command is probably unnecessary, but I like to pretend I start with a clean slate each time.

No comments: