Skip to content

Instantly share code, notes, and snippets.

@vu3rdd
Last active Mar 4, 2021
Embed
What would you like to do?
Quick and dirty bash script to create a pdf with mobius double sided printing
#!/bin/bash
# https://byorgey.wordpress.com/how-to-print-things/#m%C3%B6bius-double-sided
# https://mathlesstraveled.com/2016/01/08/a-new-way-to-read-and-print-double-sided-paper/
# https://shreevatsa.net/mobius-print/
if [ $# -eq 0 ]; then
echo $#
echo "usage: $0 pdf_file"
exit
fi
total=$(pdftk $1 dump_data | grep NumberOfPages | cut -d ':' -f 2)
half=$(echo "$total"/2 + "$total"%2 | bc)
half_p_1=$(echo $half + 1 | bc)
forward_pages=($(seq 1 1 $half))
reverse_pages=($(seq $half_p_1 1 $total))
pages=""
for i in "${!forward_pages[@]}"; do
pages+="${forward_pages[i]} "
pages+="${reverse_pages[i]} "
done
output_filename=$(basename $1 .pdf)
# now generate the pdf
pdftk $1 cat $pages output "$output_filename"_mobius.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment