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?
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?
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.
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 its 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
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
-layout flag can be added to the pdftotext command to preserve the formatting.
less FILE.pdf) resembled a binary format.
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
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 -v file.pdf.
It may be worth to consider running imgcat1. 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:
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.
1Worth adding that there are to packages with identical name, iTerm's and one that is maintained.
lesspipe file.pdf | less
lesspipe is provided by the package less on Debian and Ubuntu.
This might be helpful, please note that:
qlmanage -p <file_name>
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.
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)
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.
install imgcat, then:
imgcat -W 100% file.pdf
in case you are dealing with a multipage pdf, try this first:
pdfseparate multipage.pdf %d.pdf
This code creates multiple single-paged pdfs from the input. Here %d refers to a single-digit number to name the output (each page). Feel free to modify it. If you are not sudoer to install 'imgcat', don't worry! Here is the solution. iterm2