#!/bin/bash usage(){ echo "Usage: $(basename "$0") [FOLDER|PREFIX]" } [[ $# -lt 2 ]] && usage && exit 2 PAGE=$1 PDF=$2 DEST=${3:-.} [[ ! -f "$PDF" ]] && echo "FAILURE: File <$PDF> not found!" && exit 3 file -bi "$PDF" | grep -q "application/pdf" [[ $? -ne 0 ]] && echo "FAILURE: File <$PDF> not detected as a valid application/pdf document!" && exit 3 if [[ -d $DEST ]]; then DEST="$DEST/extract" fi if [[ "$PAGE" == *-* ]]; then START=$(echo "$PAGE" | cut -d '-' -f1) START=${START:-1} PAGINATION="-f $START" END=$(echo "$PAGE" | cut -d '-' -f2) if [[ ! -z $END ]]; then PAGINATION="$PAGINATION -l $END" fi else PAGINATION="-f $PAGE -l $PAGE" fi pdftoppm -jpeg $PAGINATION "$PDF" "$DEST"