Skip to content

Instantly share code, notes, and snippets.

@vvv
Last active August 29, 2015 14:06
Show Gist options
  • Save vvv/f46baba9a39813b29bae to your computer and use it in GitHub Desktop.
Save vvv/f46baba9a39813b29bae to your computer and use it in GitHub Desktop.
Convert PDF 2 sides per page to 1 side per page
#!/bin/bash
## SEE http://superuser.com/questions/54054/convert-pdf-2-sides-per-page-to-1-side-per-page
##
## Find out the size of a page (MediaBox). If you use Mac OS X's
## Preview app then select `Tools -> Show Inspector' in the menu or
## type `Cmd-I'.
MEDIA_BOX=612x792
INFILE=TYH.pdf
W=$((${MEDIA_BOX%x*} * 5))
H=$((${MEDIA_BOX#*x} * 10))
gs -q -o _left.pdf -sDEVICE=pdfwrite -g${W}x${H} \
-c '<</PageOffset [0 0]>> setpagedevice' -f $INFILE
gs -q -o _right.pdf -sDEVICE=pdfwrite -g${W}x${H} \
-c "<</PageOffset [-$(($W / 10)) 0]>> setpagedevice" \
-f $INFILE
pdftk A=_left.pdf B=_right.pdf \
shuffle A1-endodd B1-endodd A1-endeven B1-endeven \
output ${INFILE%.pdf}_1p.pdf
rm _left.pdf _right.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment