#!/bin/bash # ExtractPdfPages.sh # Invoke this script in the same directory as the source PDF files. # Extracts PDF pages. for file in *.pdf; do test -e "$file" || continue echo 'Processing '"$file" read -r -p'Enter first page to extract: ' fpg read -r -p'Enter last page to extract: ' lpg test $fpg -lt 1 && fpg=1 pgs=$(qpdf --show-npages "$file") test $lpg -gt $pgs && lpg=$pgs test -n "$fpg" && test -n "$lpg" && fpg=$fpg- qpdf "$file" --pages . $fpg$lpg -- "${file%.*}!.pdf" done echo -en '\a' read -rs -n1 -t60 -p'Ctrl+C to exit or any key to pause!' || { echo; exit;} echo -en '\r\aPress Ctrl+C to exit permanent hold!' sleep infinity