Created
November 1, 2024 16:39
-
-
Save KorigamiK/9169d3f5c99510908b10b5d51b0d3fc1 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Loop through all week* directories | |
for dir in week*/; do | |
# Extract week number from directory name | |
week_num=$(echo "$dir" | grep -o '[0-9]\+') | |
# Enter directory | |
cd "$dir" | |
# For each PDF in current directory | |
for pdf in *.pdf; do | |
# Skip if no PDFs found | |
[ -f "$pdf" ] || continue | |
# Get total page count | |
pages=$(pdftk "$pdf" dump_data | grep "NumberOfPages" | awk '{print $2}') | |
# Calculate range to keep (skip first 3 and last 3) | |
start=4 | |
end=$((pages - 3)) | |
# Only process if enough pages exist | |
if [ $end -gt $start ]; then | |
pdftk "$pdf" cat $start-$end output "stripped_$pdf" | |
rm "$pdf" | |
mv "stripped_$pdf" "$pdf" | |
fi | |
done | |
# Run combine-pdfs command | |
combine-pdfs | |
# Rename combined.pdf to week*.pdf | |
mv combined.pdf "week${week_num}.pdf" | |
# Move back to parent directory | |
cd .. | |
# Move the week*.pdf to current directory | |
mv "${dir}week${week_num}.pdf" . | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment