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.
Being able to view a PDF file from the Linux command-line environment is associated with the following benefits.
You might also like:
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.
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.
$ less draft.pdf
As expected, the PDF file format is retained.
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.