Created
April 30, 2016 23:57
-
-
Save pr00thmatic/e466cdc4ecb73a65a0d1078193653773 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
# thanks to Ocaso Protal! http://stackoverflow.com/questions/14704274/how-to-write-shell-script-for-finding-number-of-pages-in-pdf | |
n_pages=$(pdfinfo $1 | grep Pages | awk '{print $2}'); | |
page_width=$(pdfinfo $1 | grep "Page size" | awk '{print($3)}'); | |
page_width=$(echo "$page_width/2" | bc); | |
odd_file="tmp-$1-odd.pdf"; | |
even_file="tmp-$1-even.pdf"; | |
# generating pdf with odd pages | |
pdfjam $1 --trim "0cm 0cm $(echo $page_width)px 0cm" --clip true --outfile $odd_file --no-tidy --quiet; | |
# generating pdf with even pages | |
pdfjam $1 --trim "$(echo $page_width)px 0cm 0cm 0cm" --clip true --outfile $even_file --no-tidy --quiet; | |
# mixing up both pdfs | |
pdfjam_arguments=""; | |
for i in $(seq 1 ${n_pages}); do | |
pdfjam_arguments+="$even_file $i $odd_file $i "; | |
done | |
# i know, i know, eval is evil, but... but... i can't find another way D: | |
eval "pdfjam $pdfjam_arguments --outfile fixed-$1 --quiet"; | |
# removing temporal pdfs... | |
rm tmp-$1-even.pdf | |
rm tmp-$1-odd.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment