May 29, 2011

A short exercise in hacking and mashing PDFs

A while back I found W. Ross Ashbys Introduction to Cybernetics online as a PDF, but formatted 2-up for printing, which makes it a really bad read on the Kindle. I needed to de-n-up it. But how to. Ghostscript is able to limit the viewport on the synthetic output device pdfwrite to one page - but that only got me all the left pages.
Googling for PDF tools is about as frustrating as googling for antivirus or spamfilters - very, very spammy, tons of bad half-solutions and workarounds for people like me who don't want to pay for Adobe's tools.
After a while I found out how to fix it without downloading anything at all, as long as you're on a Mac. Here's how:


  1. Crop the pdf to left/respectively right pages only. You can do this with preview - select the right/lift page. Load the inspector (in Tools) and find the crop-tab. Crop and save as leftpages.pdf, then open the original and do the right pages as rightpages.pdf

  2. REALLY crop the pdf. What you just did only defined some metadata in the PDF that tells viewers which part of the pdf to show. This breaks down a little later in this workflow, so you need to actually cut the pdf. You can do this using Ghostscript (which I might have installed by hand using macports, I forget)

    gs -g4210x5950 -sDEVICE=pdfwrite -sOutputFile=realrightpages.pdf -dUseCropBox=true -dBATCH -dNOPAUSE -f rightpages.pdf

    The 4210 and 5950 are the width and height, respectively in pixels - for this pdf, this mac and this install of ghostscript there are 10 pixels to a point - and you can read off the point dimensions in the inspector in preview.

  3. Interleave left and right pages using the automator.

    1. Open Automator

    2. Start a new workflow

    3. Drag your files to the workflow windows, left pages first

    4. In the PDF tasks, find "Combine PDFs" and choose "shuffling" mode, which takes pages from first file and second file alternately


  4. You're done!


Posted by Claus at May 29, 2011 11:54 PM
Comments
Post a comment