Open pdf file linux terminal

View pdf file in terminal

I want to view pdf files directly on our cluster rather than copying them to my local machine and then opening them in a viewer. How can I view a pdf file in my terminal?

If you’re connectiong to the cluster with ssh, I recommend using SSHFS. It provides a common solution to all “How do I do X with remote files” issues.

10 Answers 10

In many systems less uses lesspipe, which can handle pdftotext automatically. Therefore, you can immediately try

which will show the output of pdftotext in less .

For people like me who found this and get the error «no pdftottext available» just run apt-get install pdftohtml first to get this to work. Thanks to stackoverflow.com/questions/3570591/…

I guess, it is not possible to see PDF file in terminal but you can check it’s content by converting PDF file to text. You can do this as:

It will produce a.txt file which you can read into VIM.

For ubuntu-variant, this binary is available in following package.

It is possible to see a PDF file in the terminal, like so: pdftotext -layout file.pdf — | less (that’s how Ubuntu’s default lesspipe script does it)

I tried the following with good results:

pdftotext filname.pdf - | less 

When I want to «view a pdf file in terminal», that for me means that I want to actually see an uncompressed PDF, I do:

pdftk in.pdf output out.pdf uncompress 

I always wondered why both less in.pdf and less out.pdf give me just text strings in the PDF (and excluding the text-only PDF commands I’d expect in out.pdf ).

Well, that happens because of the lesspipe assuming I want pdftotext being run first — and since here I don’t, I have to specifically disable the lesspipe by setting LESSOPEN environment variable to nothing; that is:

And finally, I can view the uncompressed PDF code using less

Yet another solution. May I recommend to you the ancient utility mc .

MC(1) GNU Midnight Commander mc - Visual shell for Unix-like systems. 

mc is designed around text-based file-management, and it has a “view” option ( F3 key) which will automatically convert .pdfs to text for viewing without a GUI. The code which does this conversion is part of mc itself, so it does not require conversion by other utilities. (Also has a native .html viewer for WIW.)

mc’s viewer is very visually attractive compared to the other options here! To view a pdf without opening the file manager, you can use the -v option like this: mc -v file.pdf .

Читайте также:  Отключить горячие клавиши astra linux

Need to work out how to suppress opening an X application for that extension though on double click. Using bottom menu is well functional.

This might be helpful, please note that:

  • It is for macOS only.
  • It won’t open the pdf inside the terminal window rather open a Quick look, which I find very powerful to see any file or documents quickly. Simply use:

Maybe similar command in Linux called (gnome-sushi) I haven’t tested this, but might be helpful as well. I will update this post after testing it.

lesspipe is provided by the package less on Debian and Ubuntu.

One more solution is to use command gnome-open

Provided that you have login your server with -X option (ssh -X)

If you run emacs on your machine ( emacs comes preinstalled on Ubuntu 18.04), you can virtually open and see a pdf on a remote server by hitting Ctrl-x Ctrl-f (to find-file ) and then type in /user@hostname:/path/to/my.pdf and hit Enter (note the very first / ). You will then be prompted to enter the server’s password and there it is! You can see the pdf inside emacs.

Navigate through PDF inside emacs

Use space to go one page down and backspace to go one page up. You can also use arrow keys to scroll through a single page if it doesn’t fit in the screen.

Zoom in by hitting Ctrl-x Ctrl-+ . Zoom in more by hitting + only. Or zoom out more by hitting — .

Yes, you can connect to a remote server from within emacs using the build-in package tramp that works as simple as I explained above. This method works, not only for pdf, but for any other type of file, such as images.

Источник

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.

Читайте также:  Linux find files in 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.

Sample PDF File Viewing

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.

View PDF in Linux Commandline

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.

Читайте также:  Linux посмотреть права группы

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

View PDF in Linux Terminal

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

Linux Open PDF

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.

About This Site

Vitux.com aims to become a Linux compendium with lots of unique and up to date tutorials.

Latest Tutorials

Источник

Оцените статью
Adblock
detector