Skip to content

Instantly share code, notes, and snippets.

@taylorpaul
Created April 23, 2024 20:53
Show Gist options
  • Save taylorpaul/7dbb2c2255641d7ca5588cf067ae60f2 to your computer and use it in GitHub Desktop.
Save taylorpaul/7dbb2c2255641d7ca5588cf067ae60f2 to your computer and use it in GitHub Desktop.
Bash Script (using pdftk) to Rip Last Page of PDF into seperate PDF and then merge all together.
#!/bin/bash
OUTDIR="./first_pass_notes"
OUTFILE="$OUTDIR/first-passes.pdf"
# Create the directory (ignore if already exitsing):
mkdir -p $OUTDIR
# Iterate through the PDF files and print the last page to our document
find . -maxdepth 1 -name "*.pdf" | while read fname ; do
echo "Working: $fname";
pdftk $fname cat r1 output $OUTDIR/first-pass-$(basename $fname);
done;
# merge all those PDFs together
pdftk $OUTDIR/*.pdf cat output $OUTFILE
# Delete all those extra pdfs if you don't want them:
rm $OUTDIR/first-pass-*.pdf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment