Skip to content

Instantly share code, notes, and snippets.

@hayamiz
Forked from pi8027/nakatoji.zsh
Created August 19, 2012 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hayamiz/3394285 to your computer and use it in GitHub Desktop.
Save hayamiz/3394285 to your computer and use it in GitHub Desktop.
中綴じ用の面付けをするスクリプト
#!/bin/zsh
[ -z $1 ] && exit -1
nakatoji_sequence(){
last=$(expr 4 \* $1)
for i in {1..$1} ; do
echo -n "$(expr $last - $i \* 2 + 2),$(expr $i \* 2 - 1),"
echo -n "$(expr $i \* 2),$(expr 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 $(expr \( $pages + 3 \) / 4)) 2>/dev/null
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment