Last active
March 4, 2021 06:52
-
-
Save vu3rdd/9b6fa387429db3a7d589998f5ba6a51b to your computer and use it in GitHub Desktop.
Quick and dirty bash script to create a pdf with mobius double sided printing
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
#!/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