63

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?

59

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

 less file.pdf

which will show the output of pdftotext in less.

| improve this answer | |
  • 1
    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/… – Ryan May 12 at 0:16
28

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:

pdftotext a.pdf

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

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

poppler-utils
| improve this answer | |
  • 7
    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) – villapx Jun 5 '17 at 13:33
6

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:

$ LESSOPEN="" less out.pdf

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

| improve this answer | |
4

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.)

| improve this answer | |
  • 1
    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. – Rachel Frei Jul 13 at 19:55
3

I tried the following with good results:

pdftotext filname.pdf - | less
| improve this answer | |
  • 1
    This works better for me on RHEL, since the lesspipe.sh script doesn't appear to support *.pdf – klugerama Nov 10 at 18:09
1

One more solution is to use command gnome-open

gnome-open youfile.pdf

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

| improve this answer | |
  • 2
    How does this view the PDF file in the terminal? – user Feb 27 '13 at 12:27
  • Not on terminal, but can view a pdf on issuing command from terminal. – bioinformatician Feb 28 '13 at 12:40
  • 5
    While that is true, the OP did specifically ask for a terminal-based approach. – user Feb 28 '13 at 20:52
1
lesspipe file.pdf | less

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

| improve this answer | |
0

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

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

Context

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.

| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.