6 # A script for searching through PDFs to find some words.
8 # I guess that everyone knows that PDFs aren't greppable. However, if you use
9 # this script, you can grep through PDFs for various key words, just as if
12 # usage: pdfgrep [pattern] [PDFs to search ...]
23 echo ${1} | grep -q -i -E '.pdf$'
26 which pdftotext &> /dev/null || die "you must have pdftotext installed"
27 which fold &> /dev/null || die "you must have fold installed"
31 #echo "PATTERN=${PATTERN}"
33 TMPDIR=`mktemp -d -t pdfgrep.XXXXXXXXXX` || exit 1
34 trap "rm -rf ${TMPDIR}; exit" INT TERM EXIT
37 if ispdf "${PDF}"; then
39 pdftotext "${PDF}" "${TMPDIR}/${PDF}.pre.txt"
40 fold -s -w 120 "${TMPDIR}/${PDF}.pre.txt" > "${TMPDIR}/${PDF}.txt"
41 grep --with-filename -i --color=always \
42 ${PATTERN} "${TMPDIR}/${PDF}.txt" | \
44 rm -f "${TMPDIR}/${PDF}.txt"