#!/bin/zsh function pdf_num_pages { gs -q -dNOSAFER -dNODISPLAY -c "($1) (r) file runpdfbegin pdfpagecount = quit" } function pdf_extract_range { yes | gs -q -dBATCH -sOutputFile="$4" -dFirstPage=$2 -dLastPage=$3 -sDEVICE=pdfwrite "$1" }