for those who don't have a scanner that can do two-sided scans, but still want to make PDFs:
1) put your even pages in one directory, and your odd pages in another.
2) say ./collate
Depends on the makepdf script above (my modded one). I called mine makepdf (no .sh) and added it to my path. You'll probably have to do the same, or edit this script to give it the full path to your makepdf script.
Code:
#!/bin/bash
# FILE : collate
# Function: takes two directories full of odd and even pages and makes one
# PDF out of them.
# I assume the following file naming convention: P xxx.ext, where xxx is a
# 3-digit number.
# Chris Reitz
#
# ask for some user input
read -p "Please enter location of odd-numbered pages [Odd] : " odd_dir;
read -p "Please enter location of even-numbered pages [Even] : " even_dir;
read -p "image file extension [jpg] : " imagetype;
# provide defaults for UI
if [[ `expr length "$odd"` = 0 ]]
then
odd_dir=Odd ;
fi;
if [[ `expr length "$even"` = 0 ]]
then
even_dir=Even ;
fi;
if [[ `expr length "$imagetype"` = 0 ]]
then
imagetype=jpg ;
fi;
mkdir Collated ;
# Make the odd pages odd.
#
# The set of odd numbers is given by
#
# SIGMA(0, Inf, n, 2*n-1)
#
echo "collating odd pages..." ;
cd $odd_dir ;
for i in *.${imagetype} ;
do
str="$i" ;
index_num=10#${str:2:3} ;
let odd_num=2*index_num-1 ;
while [[ `expr length "$odd_num"` -lt 3 ]]
do
odd_num='0'$odd_num ;
done ;
cp "$i" ../Collated/"$odd_num".${imagetype} ;
done;
# Make the even pages even.
#
# The set of even numbers is given by
#
# SIGMA(0, Inf, n, 2*n)
#
echo "collating even pages..." ;
cd ../$even_dir ;
for i in *.${imagetype} ;
do
str="$i" ;
index_num=10#${str:2:3} ;
let even_num=2*index_num ;
while [[ `expr length "$even_num"` -lt 3 ]]
do
even_num='0'$even_num ;
done ;
cp "$i" ../Collated/"$even_num".${imagetype} ;
done;
# Use the makepdf script to turn the whole lot into one ginormous
# not-so-portable document.
cd .. ;
read -p "Make images into a PDF? (Y/n) [y] : " ask;
if [[ "$ask" = "n" ]]
then
echo "Nothing left to do. Exiting." ;
else
cd Collated ;
makepdf ;
mv *.pdf .. ;
fi;
read -p "Delete original images? (Y/n) [n] : " ask;
if [[ "$ask" = "y" ]]
then
read -p "Are you sure? (Y/n) [n] : " askagain;
if [[ "$askagain" = "y" ]]
then
rm -rf "$odd_dir" ;
rm -rf "$even_dir" ;
else
echo "Nothing left to do. Exiting." ;
fi;
else
echo "Nothing left to do. Exiting." ;
fi;
read -p "Delete collated images? (Y/n) [n] : " ask;
if [[ "$ask" = "y" ]]
then
read -p "Are you sure? (Y/n) [n] : " askagain;
if [[ "$askagain" = "y" ]]
then
rm -rf "./Collated" ;
else
echo "Nothing left to do. Exiting." ;
fi;
else
echo "Nothing left to do. Exiting." ;
fi;
exit
I know it's not the world's most efficient code, but hey! it works. And it's my first working bash script, after one that parroted back my CPU temperature at me every second.