Skip to content

Instantly share code, notes, and snippets.

@cburgmer
Created January 6, 2019 16:22
Show Gist options
  • Save cburgmer/97a351542f6e9ba7a9a5ddffa29554ff to your computer and use it in GitHub Desktop.
Save cburgmer/97a351542f6e9ba7a9a5ddffa29554ff to your computer and use it in GitHub Desktop.
Scan two sided documents with a one-side only scanner
#!/bin/bash
readonly TMP_DIR="/tmp/rearrange_double_sided_scan.$$"
pages_rearranged() {
local dir="$1"
local count
count=$(( $(ls "$dir" | wc -l) / 2 ))
paste -d '\n' \
<(ls "$TMP_DIR" | sort -n | head -n "$count") \
<(ls "$TMP_DIR" | sort -n | tail -r -n "$count")
}
main() {
local source_file="$1"
mkdir "$TMP_DIR"
pushd "$TMP_DIR" > /dev/null
pdfseparate "$source_file" "%d"
mv "$source_file" "${source_file/.pdf/}.original.pdf"
pdfunite $(pages_rearranged .) "$source_file"
popd > /dev/null
rm "$TMP_DIR"/*
rmdir "$TMP_DIR"
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment