- Command to open pdf files in bash scripting
- 3 Answers 3
- How do I open a PDF in a Linux terminal?
- Installation of Evince Command
- Ubuntu/Debian-based Operating Systems
- CentOS/Fedora/RHEL-based Operating Systems
- Arch Linux based Operating Systems
- Syntax
- Example
- Conclusion
- About the author
- Shehroz Azam
- How to View PDF File in Linux Command Line
- Why View PDF File in Linux Command Line
- Problem Statement
- Method 1: View PDF File Using less Command
- Method 2: Combining pdftotext and less Commands
- How to Open a PDF in Linux Mint 20 Terminal
- Opening a PDF in the Linux Mint 20 Terminal
- Step # 1: Carry out a System Update
- Step # 2: Install Evince on your System
- Step # 3: Use Evince to Open a PDF in your Linux Mint 20 Terminal:
- Bonus Tip
- Conclusion
- Search
- About This Site
- Latest Tutorials
Command to open pdf files in bash scripting
could anybody suggest me any simple linux command to open pdf files(text only) on command line. If we are able to pass the password as an argument to the command that would be more appreciated. I am trying to build a script that iterates all the possible 4 character passwords, to crack password of a password protected pdf file. Thanks in Advance Harsha
yes, I am trying to build a script that iterates all the possible 4 character passwords, to crack password of a password protected pdf file.
3 Answers 3
To read PDFs on the terminal you could use a framebuffer PDF viewer like fbgs (based on the fbi image viewer and gs). From the home page:
fbgs : A wrapper script for viewing ps/pdf files on the framebuffer console using fbi.
If X applications are allowed just call the users default PDF viewer using
If you want do do further PDF manipulations hava a look at pdftk , it allows to set the password and many more features.
pdftotext is part of the xpdf package. It’ll output to a text file. If no output file is specified, you’ll end up with a file of the same name, but a ‘.txt’ extension.
pdftotext -layout file.pdf [output.txt]
You can pass passwords to it.
man pdftotext |grep -i password -opw password Specify the owner password for the PDF file. Providing this will bypass all security restrictions. -upw password Specify the user password for the PDF file.
If your goal is to open the pdf into a terminal, you can use Zathura, but it requires X11 anyway! You can’t see a pdf without a properly installed graphical interface.
If you want to open a pdf into another window, you can simply call an external program like evince; in this case, you simply use the terminal to choose the pdf to open and nothing more.
EDIT: I found this link, I think this could solve your problem!
My requirement is to check if the entered password is can open a the password protected pdf file. I guess i wont be able to do that with evince!!
Ops, I have just seen your comment. I think you should study how to create and read a pdf from zero. but in this way it’s much more complex.
How do I open a PDF in a Linux terminal?
“Evince” is the program used for opening and rendering a PDF document for viewing purposes only in a Linux terminal. It is GNOME’s default document viewer, so it comes pre-installed in the latest versions of GNOME. This post will briefly introduce the evince command and learn how to install evince in any Linux Operating system, the right syntax to use evince command, and how to use the evince command to open a PDF file in a Linux terminal.
Installation of Evince Command
If “evince” is not installed on your Linux Operating system, you can install it using the following commands based on your Operating system.
Ubuntu/Debian-based Operating Systems
For Ubuntu or Debian based Operating system, you can execute the command typed below to install evince:
CentOS/Fedora/RHEL-based Operating Systems
For the latest versions of CentOS, Fedora, or and RHEL-based Operating systems, the following command can be used for installing evince:
Arch Linux based Operating Systems
Arch Linux based Operating system users can execute the below-given command for installing evince without having the sudo privileges:
Syntax
The syntax is really simple and easy.
Example
Suppose we have a PDF file “file.pdf” in the Downloads directory.
To Open the “file.pdf” file, either first navigate to the directory using the cd command:
Execute the evince command by providing it the PDF file’s name:
Or directly provide the file name and path to the evince command to open a PDF file from anywhere in a Linux terminal.
After providing a PDF file and executing the evince command, the PDF file will open up.
If you want to explore more about the evince command, you can walk through the man page of the evince command using the command typed below:
Conclusion
The evince command is a default document viewer of GNOME, and it can be used for viewing any document like images, PDF files, and URLs. In this post, we have learned to open a PDF in the Linux terminal using the evince command. If you want to learn more about the usage of the evince command, feel free to read the man page and use it to your exact needs.
About the author
Shehroz Azam
A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.
How to View PDF File in Linux Command Line
Please note that this article seeks to explore viable ways of viewing (not opening) a PDF file from the Linux command-line environment. The creation of the PDF or Portable Document Format file type was inspired to solve/lessen the hurdles that made document sharing between operating systems and computers difficult.
Why View PDF File in Linux Command Line
Being able to view a PDF file from the Linux command-line environment is associated with the following benefits.
- PDF maintains a document’s format. Once a document is created and saved in a PDF format, it cannot be altered like documents existing in .txt or .docx formats. Therefore, viewing such a document from the Linux command line environment should be the same as viewing it from a graphical PDF document reader.
- PDF files are comparatively smaller than other document file formats making it easy for the Linux terminal environment to accommodate them.
- Not all Linux users are tied to a Desktop environment where access to a graphical PDF reader application is easy. For users or Linux administrators bound to a Linux server operating system environment, this approach makes it easy to relatively preview PDF documents like receipts and invoices.
You might also like:
Problem Statement
We are going to need a sample PDF file which we will try to open and view from the Linux operating system command line.
The preview of the above file is from a graphical PDF reader application installed on a Linux operating system.
Let us break down the approaches to viewing PDF files from a Linux terminal.
Method 1: View PDF File Using less Command
The GNU General Public License makes it possible to use less utility from the Linux terminal to read input files. In comparison to graphical text editors like vi and nano, less command takes a shorter duration to read and display the targeted file on the Linux terminal window.
To view our PDF file (draft.pdf), we will run the following command.
As expected, the PDF file format is retained.
Method 2: Combining pdftotext and less Commands
As stated on its naming convention, the pdftotext command utility is primarily effective in converting a PDF file to a text file.
Its usage syntax is as follows:
$ pdftotext [options] [PDF-file [text-file]]
However, we are not primarily interested in converting our sample PDF file to a text file format. We, therefore, need to temporarily convert the sample PDF file to a text file and then pipe the converted text file to the less command for viewing/display on the Linux terminal window.
Our modified syntax for this approach is as follows:
$ pdftotext [options] [PDF-file] - | less
The final implementation of the above command is as follows:
$ pdftotext draft.pdf - | less
We have successfully learned how to read a PDF file as input and display/view it on a Linux command-line window.
How to Open a PDF in Linux Mint 20 Terminal
Evince is a relatively new document viewer that was developed with the intention of integrating multiple document viewers into one single tool. It was done so that you do not need a different document viewer for every different type of document. Moreover, this tool lets you view your documents within the Linux terminal. In this article, we will show you how you can open a PDF in Linux Mint 20 terminal using this tool.
Opening a PDF in the Linux Mint 20 Terminal
To open a PDF instantly in your Linux Mint 20 terminal, you have to follow the steps listed below:
Step # 1: Carry out a System Update
First, you should quickly update your system with the following command:
Step # 2: Install Evince on your System
After updating your system, you need to install a tool on it known as “Evince”. This tool can be installed by executing the command shown below:
It is an extremely lightweight tool which is why it will hardly take a minute to install it on your Linux Mint 20 system after which you will see the following messages on your screen.
Step # 3: Use Evince to Open a PDF in your Linux Mint 20 Terminal:
Now when “Evince” has been successfully installed on your Linux Mint 20 system, you can use it to open a PDF in your terminal by executing the command shown below:
Replace “File” with the name of that particular PDF that you want to open up in your terminal followed by the “.pdf” extension.
After executing this command, your PDF will instantly open in the terminal as shown in the following image:
Bonus Tip
The “Evince” tool can be used to open your PDFs from the Linux terminal, however, if you want to remove this tool completely from your system, then you can quickly execute the command shown below:
$ sudo apt-get purge --autoremove evince
Conclusion
This article provided you with one very common use case of the “Evince” tool in Linux Mint 20 i.e. opening a PDF from the Linux terminal. In the very same manner, you can also view any other supported document type too while making use of this tool. Moreover, we have also shared with you the removal method of this tool from your Linux Mint 20 system in this article.
Search
About This Site
Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.