Created
May 28, 2014 18:13
-
-
Save jmiserez/8c79101bfe8566a818db to your computer and use it in GitHub Desktop.
Annotate LectureNotes PDFs
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 | |
mkdir /tmp/magick_tmp | |
MAGICK_TMPDIR=/tmp/magick_tmp | |
export MAGICK_TMPDIR | |
LECTURENOTESDIR=/home/ec2-user/Dropbox/LectureNotes/ | |
cd $LECTURENOTESDIR | |
process_directory() { | |
BASE_NAME="$@" | |
# echo "$BASE_NAME" | |
PDF_NAME="$BASE_NAME"".original.pdf" | |
# echo "$PDF_NAME" | |
if [ -f "$PDF_NAME" ]; | |
then | |
# echo "File $PDF_NAME exists." | |
if [ ! -f "$BASE_NAME"".annotated.pdf" ]; then | |
rm -f "$BASE_NAME"".annotated.pdf" | |
rm -f lclayer2.pdf | |
rm -f lclayer3.pdf | |
rm -f lclayer4.pdf | |
rm -f lclayer12.pdf | |
rm -f lclayer123.pdf | |
rm -f lclayer1234.pdf | |
convert *_2.png lclayer2.pdf | |
if [ $? -ne 0 ]; then | |
# echo "layer 2 does not exist" | |
cp "$PDF_NAME" "$BASE_NAME"".annotated.pdf" | |
else | |
pdftk "$PDF_NAME" multistamp lclayer2.pdf output lclayer12.pdf | |
rm -f lclayer2.pdf | |
convert *_3.png lclayer3.pdf | |
if [ $? -ne 0 ]; then | |
# echo "layer 3 does not exist" | |
mv lclayer12.pdf "$BASE_NAME"".annotated.pdf" | |
else | |
pdftk lclayer12.pdf multistamp lclayer3.pdf output lclayer123.pdf | |
rm -f lclayer3.pdf | |
rm -f lclayer12.pdf | |
convert *_4.png lclayer4.pdf | |
if [ $? -ne 0 ]; then | |
# echo "layer 4 does not exist" | |
mv lclayer123.pdf "$BASE_NAME"".annotated.pdf" | |
else | |
pdftk lclayer123.pdf multistamp lclayer4.pdf output lclayer1234.pdf | |
rm -f lclayer4.pdf | |
rm -f lclayer123.pdf | |
mv lclayer1234.pdf "$BASE_NAME"".annotated.pdf" | |
fi | |
fi | |
fi | |
fi | |
# else | |
# echo "File $PDF_NAME does not exist." | |
fi | |
} | |
recurse_subdir(){ | |
if [ "$#" -eq 1 ]; then | |
process_directory $1 | |
fi | |
for i in *; do | |
if [ -d "$i" ]; then | |
# echo "$i" | |
cd "$i" | |
recurse_subdir "$i" | |
cd ../ | |
fi | |
done | |
} | |
recurse_subdir | |
rm -rf /tmp/magick_tmpdir/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment