Created
November 13, 2015 12:44
-
-
Save berteh/45ca6c8ebfc3fa97cde0 to your computer and use it in GitHub Desktop.
bash shortcut (alias/functions) to turn pdf to booklet or cardset.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pdf shortcuts, using pdftk | |
pdfcount(){ | |
#return number of pages of a pdf file | |
pdftk $1 dump_data output | grep -i NumberOfPages | grep -oE "[[:digit:]]{1,}" | |
} | |
pdf2booklet16(){ | |
# reorder a copy of given pdf to be printed as 2 pages/side + dual, and binded in booklets of 4 sheets (16 pages). | |
# input.pdf must contain a multiple of 16 pages. | |
# staple each 4 pages together in the middle and you're done. | |
count=`pdfcount $1` | |
if [ $((count % 16)) -ne 0 ] | |
then | |
echo "Usage: pdf2bookletDual2BySide <input.pdf> where input.pdf must contain a multiple of 16 pages" | |
return | |
fi | |
i=1 | |
r=$(($count+1)) | |
seq=" " | |
while [ $i -le $count ] | |
do #each sheet is a sequence of 4 pages: last | first | second | before-last | |
seq="$seq $((r-i)) $((i)) $((i+1)) $((r-i-1)) $((r-i-2)) $((i+2)) $((i+3)) $((r-i-3)) $((r-i-4)) $((i+4)) $((i+5)) $((r-i-5)) $((r-i-6)) $((i+6)) $((i+7)) $((r-i-7)) " | |
#alternative sequence if your printer duplex unit puts the print first face up. | |
#seq="$seq $((i+1)) $((r-i-1)) $((r-i)) $((i)) $((i+3)) $((r-i-3)) $((r-i-2)) $((i+2)) $((i+5)) $((r-i-5)) $((r-i-4)) $((i+4)) $((i+7)) $((r-i-7)) $((r-i-6)) $((i+6)) " | |
i=$((i+16)) #each binding is 4 sheets (16 pages) | |
done | |
echo "creating booklet in $1_book.pdf" | |
pdftk $1 cat $seq output $1_book.pdf | |
} | |
alias 'rmlinks'='find . -maxdepth 1 -type l -exec rm -f {} \;' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment