Guest User

sigpgs.sh

a guest
Jun 17th, 2020
66
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. label="SigPage" # To be inserted between filename and indices
  4. npg=$(wc -l < "$2") # Count the number of signatories
  5. spg=$3 # Read the page number where signature pages begin
  6. epg=$(expr $spg + $npg - 1)
  7. filename=$(basename "$1" .pdf) # Get filename sans extension
  8.  
  9. # Split PDF into separate & numbered pages
  10. cd "$(dirname "$1")"
  11. mkdir "$filename"
  12. qpdf --split-pages "$1" --pages . $spg-$epg -- ./"$filename"/_%d
  13.  
  14. # Rename split pages
  15. c=0
  16. while read s
  17. do
  18.     c=$(expr $c + 1)
  19.     # Zero-padding indices where there're 10+ signatories
  20.     if [ $npg -gt 9 ]
  21.     then
  22.         cc=$(printf "%02d" $c)
  23.     else
  24.         cc=$c
  25.     fi
  26.     newname=$(echo "$filename""_""$label""_""$cc""_""$s"".pdf")
  27.     mv "./$filename/_$cc" "./$filename/$newname"&&\
  28.     echo "[Output] $newname"
  29. done < "$2"
RAW Paste Data