While I initially wanted to create a Python program for searching multiple PDF files, I came across a much simpler commandline solution that outputs nice colour coded string matches when searching PDF files. Linux really is wonderful in this respect. MacOS also supports pdfgrep.
PDF Grep
First install it:
sudo apt-get install -y pdfgrep
Then open up a terminal and search with this syntax:
pdfgrep <flags> <search string> <path where the PDF files are>
So if I'm searching for "Bommasani", I'd use:
pdfgrep -Ri 'Bommasani' .
The "R" is for a recursive search which also follows symlinks. If you don't want symlinks to be explored, you can use "r". The "i" is for not being case sensitive. There are more such parameters you can see if you type:
man pdfgrep
Enjoy this simple way of searching PDF's.
Purely commandline
If pdfgrep isn't available for whatever reason, you could try:
find /path -name '*.pdf' -exec sh -c 'pdftotext "{}" - | grep --with-filename --label="{}" --color "your search string"' \;
Windows
You can use Agent Ransack or dnGREP or even Adobe Acrobat Reader which has an advanced search menu for "All PDF Documents in" and specifying the folder.

No comments:
Post a Comment