Originally Posted by
GOwin
Is there a way to get the page numbers of the keyword hits?
I do not know of any modification to the command-line in your post that will show the page number of search-string matches. Perhaps another forum member will be able to help with this.
Just to practice, I wrote the following shell script, which is a bit involved but does what you want. The user enters the search string as a command-line parameter, and the script returns the page number and file name of any search-string matches.
This shell script uses the pdfinfo utility. If not already installed, it's available in the repo's as part of poppler-utils and xpdf-utils packages.
Code:
#!/bin/bash
[ "$*" ] || { echo "You forgot a search string!" ; exit 1 ; }
found=1
for file in *.pdf ; do
[ "$file" = '*.pdf' ] && echo "No PDF files found!" && exit 1
pages=$(pdfinfo "$file" | awk '/Pages:/ { print $NF }')
for ((i=1 ; i<=$pages ; i++)) ; do
match=$(pdftotext -q -f $i -l $i "$file" - | grep -m 1 "$*")
[ "$match" ] && echo "Page $i in $file" && found=0
done
done
[ "$found" -ne 0 ] && echo "No search string matches found"
Bookmarks