Skip to content

Instantly share code, notes, and snippets.

@hayamiz

hayamiz/nakatoji.zsh

Forked from pi8027/nakatoji.zsh
Created Aug 19, 2012
Embed
What would you like to do?
中綴じ用の面付けをするスクリプト
#!/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