Is there a way to search pdf files using the power of grep, without converting to text first in Ubuntu?
Use the Search window to look for words or document properties across multiple PDFs, use advanced search options, and search PDF indexes. Display the Find toolbar Open it by choosing Edit > Find (Ctrl/Command+F).
Dervin ThunkFile Search Tool For Windows 7
Dervin Thunk
Pdf Search Tool
14 Answers
Install the package pdfgrep, then use the command:
——————
Simpliest way is
Mac Search Tool For Multiple Pdf Files
If you have poppler-utils installed (default on Ubuntu Desktop), you could 'convert' it on the fly and pipe it to grep:
This won't create a .txt file.
wagwagpdfgrep was written for exactly this purpose and is available in Ubuntu.
It tries to be mostly compatible to grep and thus provides 'the power of grep', only specialized for PDFs. That includes common grep options, such as --recursive, --ignore-case or --color.
In contrast to pdftotext | grep, pdfgrep can output the page number of a match in a performant way and is generally faster when it doesn't have to search the whole document (e.g. --max-count or --quiet).
The basic usage is:
where PATTERN is your search string and FILE a list of filenames (or wildcards in a shell).
See the manpage for more infos.
No.
A pdf consists of chunks of data, some of them text, some of them pictures and some of them really magical fancy XYZ (eg. .u3d files). Those chunks are most of the times compressed (eg. flat, check http://www.verypdf.com/pdfinfoeditor/compression.htm). In order to 'grep' a .pdf you have to reverse the compression aka extract the text.
You can do that either per file with tools such as pdf2text and grep the result, or you run an 'indexer' (look at xapian.org or lucene) which builds an searchable index out of your .pdf files and then you can use the search engine tools of that indexer to get the content of the pdf.
But no, you can not grep pdf files and hope for reliable answers without extracting the text first.
Recoll can search PDFs. It doesn't support regular expressions, but it has lots of other search options, so it might fit your needs.
Michael Mrozek♦
Take a look at the common resource grep tool crgrep which supports searching within PDF files.
It also allows searching other resources like content nested in archives, database tables, image meta-data, POM file dependencies and web resources - and combinations of these including recursive search.
try this
for printing the lines the pattern occurs inside the pdf
enzotibcd to your folder containing your pdf-file and then..
or if you want to search in more than just one pdf-file (e.g. in all pdf-files in your folder)
or
There is a duplicate question on StackOverflow. The people there suggest a variation of harish.venkarts answer:
The advantage over the similar answer here is the --with-filename flag for grep. This is somewhat superior to pdfgrep as well, because the standard grep has more features.
Here is a quick script for search pdf in the current directory :
I assume you mean tp not convert it on the disk, you can convert them to stdout and then grep it with pdftotext. Grepping the pdf without any sort of conversion is not a practical approach since PDF is mostly a binary format.

In the directory:
or in the directory and its subdirectories:
Also because some pdf are scans they need to be OCRed first. I wrote a pretty simple way to search all pdfs that cannot be greped and OCR them.
I noticed if a pdf file doesn't have any font it is usually not searchable. So knowing this we can use pdffonts.
First 2 lines of the pdffonts are the table header, so when a file is searchable has more than two line output, knowing this we can create:
then paste this
then make it executable
then list all non-searchable pdfs in the directory:
or in the directory and its subdirectories:
Eduard FlorinescuEduard FlorinescuIf you just want to search for pdf names/properties... or simple strings that are not compressed or encoded then instead of strings you can use the below
From grep --help:
and cat --help:
gpdf might be what you need if you're using Gnome! Check this in case you're not using Gnome. It's got a list of CLI pdf viewers. Then you can use grep to find some pattern.