Shell scripting fun: pdfsplit

Posted on June 7, 2011 by Tommy McGuire
Labels: shell
Like various other people, I have been irritated by the problems with viewing two-column PDF files on a Kindle. Yesterday, however, I ran across pdfsplit, which made me decide to do something about it.

I downloaded the package, which is Cabal-ized Haskell (!), and like my other adventures with Cabal, it failed to build. Naturally, I took a peek at the code, and found it to be a very simple script that used some libraries I apparently don't have (or have and don't know it; or something).

I like writing Haskell as much as anyone, but sometimes the right tool really is a hammer. In that spirit, here is a Bourne shell script:
# pdfsplit - create a single-column version of a 2-column PDF file

if [ $# -lt 1 ]
echo "Usage: $0 file.pdf ..."
echo " Produces file-split.pdf ..."
exit 1

for input in "$@"

base=`basename $input .pdf`
pages=`pdfinfo $input | grep Pages | awk '{print $2}'`

cat <<eof >$tmp

while [ $n -le $pages ]

cat <<eof >>$tmp
\\includepdf[pages=$n,noautoscale,offset=2.125in 0]{$input}
\\includepdf[pages=$n,noautoscale,offset=-2.125in 0]{$input}


cat <<eof >>$tmp

pdflatex $tmp

rm -f $tmp $base-split.aux $base-split.log


To use it, you will need pdflatex, the pdfpages package, and pdfinfo (from the poppler-utils package on my Ubuntu laptop).
active directory applied formal logic ashurbanipal authentication books c c++ comics conference continuations coq data structure digital humanities Dijkstra eclipse virgo electronics emacs goodreads haskell http java job Knuth ldap link linux lisp math naming nimrod notation OpenAM osgi parsing pony programming language protocols python quote quotes R random REST ruby rust SAML scala scheme shell software development system administration theory tip toy problems unix vmware yeti
Member of The Internet Defense League
Site proudly generated by Hakyll.