Skip to content

Instantly share code, notes, and snippets.

@fakuivan
Last active August 28, 2020 13:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fakuivan/71080a13207dda173674594e68e165e0 to your computer and use it in GitHub Desktop.
Save fakuivan/71080a13207dda173674594e68e165e0 to your computer and use it in GitHub Desktop.
Bash function to get the number of pages in pdf files
pdfpages () {
if [[ $# -ne 1 ]]; then
echo "$FUNCNAME: expected one argument, got $#"
return 1
fi
local filename="$1"
while read line; do
if [[ "$line" =~ ^Pages:" "+([0-9]+)$ ]]; then
echo "${BASH_REMATCH[1]}"
return 0
fi
done < <(pdfinfo -- "$filename")
echo "$FUNCNAME: failed to read number of pages using command pdfinfo"
return 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment