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?

4,820 10 10 gold badges 36 36 silver badges 42 42 bronze badges asked Jun 22, 2012 at 10:27 bioinformatician bioinformatician 1,043 1 1 gold badge 7 7 silver badges 9 9 bronze badges Commented Jun 22, 2012 at 12:03

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.

Commented Jun 23, 2012 at 0:49 Render PDF to framebuffer Commented Feb 7, 2019 at 15:55

11 Answers 11

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 .

answered Jun 22, 2012 at 10:49 Jari Laamanen Jari Laamanen 2,461 17 17 silver badges 13 13 bronze badges

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/…

Commented May 12, 2020 at 0:16

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 
25k 31 31 gold badges 98 98 silver badges 145 145 bronze badges answered Jun 22, 2012 at 10:40 15k 14 14 gold badges 67 67 silver badges 101 101 bronze badges

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)

Commented Jun 5, 2017 at 13:33

I tried the following with good results:

pdftotext filname.pdf - | less 
answered Feb 7, 2019 at 15:44 4,396 3 3 gold badges 20 20 silver badges 31 31 bronze badges This works better for me on RHEL, since the lesspipe.sh script doesn't appear to support *.pdf Commented Nov 10, 2020 at 18:09 The -layout flag can be added to the pdftotext command to preserve the formatting. Commented Jun 2, 2022 at 9:08 @klugerama On Fedora (38) a PDF file opened in less ( less FILE.pdf ) resembled a binary format. Commented Jun 16, 2023 at 9:03

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

3,171 1 1 gold badge 24 24 silver badges 24 24 bronze badges answered Feb 20, 2013 at 20:14 6,868 15 15 gold badges 63 63 silver badges 72 72 bronze badges

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

23.5k 27 27 gold badges 75 75 silver badges 124 124 bronze badges answered Nov 12, 2017 at 19:10 Richard Sonnenfeld Richard Sonnenfeld 69 2 2 bronze badges

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 .

Commented Jul 13, 2020 at 19:55

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

Commented Dec 8, 2022 at 4:14

This might be helpful, please note that:

qlmanage -p

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.

answered Jun 2, 2021 at 4:08 161 3 3 bronze badges

It may be worth to consider running imgcat 1 . You mentioned that you want to browse remote files. This solution doesn't meet your requirements to view files directly on the cluster but I reckon it may pass as acceptable. Using wget you can pass outputs into the stdout and then pipe it to imgcat as follows:

wget -O- -q https://www.nceas.ucsb.edu/sites/default/files/2020-04/colorPaletteCheatsheet.pdf | imgcat 

This will produce the following results:

Example

Remarks

Again, this is not great solution as you will need to download the file (even if you are just piping it) and imgcat makes it fiddly to look at specific page in PDF. Nevertheless, I reckon it's worth to post this solution as this little trick comes in handy when dealing with PDFs that contain images, etc.

1 Worth adding that there are to packages with identical name, iTerm's and one that is maintained.

answered Apr 21, 2023 at 13:46 343 1 1 silver badge 9 9 bronze badges
lesspipe file.pdf | less 

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

answered Dec 4, 2019 at 3:47 448 1 1 gold badge 4 4 silver badges 9 9 bronze badges

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)

answered Feb 27, 2013 at 9:05 bioinformatician bioinformatician 1,043 1 1 gold badge 7 7 silver badges 9 9 bronze badges How does this view the PDF file in the terminal? Commented Feb 27, 2013 at 12:27 Not on terminal, but can view a pdf on issuing command from terminal. Commented Feb 28, 2013 at 12:40 While that is true, the OP did specifically ask for a terminal-based approach. Commented Feb 28, 2013 at 20:52

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.