search pdf file in linux

How to Search PDF File in Linux

Sometimes you may need to search PDF file for text contents. Although Adobe acrobat provides this feature, many user may not have it installed on their system. In this article, we will learn how to search PDF file in Linux. You can use this method to grep PDF files on your system. We will use pdfgrep for this purpose.

How to Search PDF File in Linux

Here is the command to install pdfgrep utility in Linux.

# Ubuntu/Debian
$ sudo apt update
$ sudo apt install pdfgrep

# Redhat/Fedora/SUSE
$ sudo dnf -y install pdfgrep

Once you have installed pdfgrep, you can easily search for a text with the following command.

$ pdfgrep pattern pdf_file_path

For example, here is the command to search for text ‘burger’ in file menu.pdf using the following command.

$ pdfgrep burger menu.pdf
$ pdfgrep 'burger' menu.pdf

Please note, if you provide only the filename, pdfgrep will look for the file in your present working directory. If your is located elsewhere, please provide the full path to file.

You can also use wildcard characters in pattern as well as filenames. Here is an example to search for text ‘burger’ in all .pdf files in your present working directory.

$ pdfgrep burger *.pdf

Here is a command to check for patterns beginning with burger in file menu.pdf.

$ pdfgrep burger* menu.pdf

You can also use pdfgrep with other commands such as find, to search for specific pdf files for a pattern. Here is the syntax to do so.

find /path -iname '*.pdf' -exec pdfgrep pattern {} +

Here is the command to search for text ‘burger’ in all .pdf files in /home folder.

find /home -iname '*.pdf' -exec pdfgrep burger {} +

In the above command, we have learnt how to search for text in PDF documents. You can run this command directly from terminal, add it to shell script, or include it in your application.

Also read:

How to Schedule Task in Python
How to Import Python Modules by String Name
Call Python Function by String Name
How to Save Git Username & Password
How to Get Classname of Instance in Python

Leave a Reply

Your email address will not be published.