Skip to content

Instantly share code, notes, and snippets.

@k-nut
Created April 21, 2018 06:37
Show Gist options
  • Save k-nut/c6e20a0cef87e3a851af0c2a83ea2415 to your computer and use it in GitHub Desktop.
Save k-nut/c6e20a0cef87e3a851af0c2a83ea2415 to your computer and use it in GitHub Desktop.
Turn a scanned duplex pdf [1,2,3,5,6,4] into the correct order [1,2,3,4,5,6]
#!/bin/sh
FILENAME="$1"
COUNT=$(pdfinfo "$FILENAME" | awk '$1 == "Pages:" {print $2}')
HALF=$((COUNT/2))
ARGUMENTS=""
for i in $(seq 1 $HALF)
do
ARGUMENTS="$ARGUMENTS Reorder-Page-$i.pdf"
done
for i in $(seq $COUNT -1 $((HALF+1)))
do
ARGUMENTS="$ARGUMENTS Reorder-Page-$i.pdf"
done
for i in $(seq 1 $COUNT)
do
pdfseparate -f $i -l $i "$FILENAME" "Reorder-Page-$i.pdf"
done
pdfunite $ARGUMENTS "$2"
rm Reorder-Page-*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment