Skip to content

Instantly share code, notes, and snippets.

@pi8027
Last active October 8, 2015 03:38
Show Gist options
  • Save pi8027/3272100 to your computer and use it in GitHub Desktop.
Save pi8027/3272100 to your computer and use it in GitHub Desktop.
中綴じ用の面付けをするスクリプト
#!/bin/zsh
[ -z $1 ] && exit -1
nakatoji_sequence(){
last=$((4 * $1))
for i in {1..$1} ; do
echo -n "$(($last - $i * 2 + 2)),$(($i * 2 - 1)),"
echo -n "$(($i * 2)),$((1 + $last - $i * 2)),"
done | sed "s/,$//g"
}
file=$(echo $1 | sed "s/\.pdf$//g")
pages=$(pdfinfo $file.pdf | grep Pages | sed "s/^.*: *//g")
pdfjam --outfile /dev/stdout $file.pdf -,{},{},{} 2>/dev/null | \
pdfjam --nup 2x1 --landscape --outfile ${file}_nakatoji.pdf \
/dev/stdin $(nakatoji_sequence $((( $pages + 3 ) / 4))) 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment