CLI pdf viewer for linux
Solution 1
Hi I think that you don't need to write a program for your purpose I mean reading pdf file in console mode because less
command already do it for you. So use it and just enjoy it.
less "the name of pdf file"
Solution 2
Ok, you asked to know even "crappy" ones. Here are two (decide yourself about their respective crappiness):
First: Ghostscript's txtwrite
output device
gs \
-dBATCH \
-dNOPAUSE \
-sDEVICE=txtwrite \
-sOutputFile=- \
/path/to/your/pdf
Second: XPDF's pdftotext
CLI utility (better than Ghostscript):
pdftotext \
-f 13 \
-l 17 \
-layout \
-opw supersecret \
-upw secret \
-eol unix \
-nopgbrk \
/path/to/your/pdf
- |less
This will display the page range 13 (first page) to 17 (last page), preserve the layout of a double-password protected named PDF file (using user and owner passwords secret and supersecret), with Unix EOL convention, but without inserting pagebreaks between PDF pages, piped through less...
pdftotext -h
displays all available commandline options.
Of course, both tools only work for the text parts of PDFs (if they have any). Oh, and mathematical formula also won't work too well... ;-)
Edit: I had mis-typed the command above (originally using pdftops
instead of pdftotext
).
Solution 3
There is also the green PDF viewer. There is a demo on YouTube.
Solution 4
Try fbgs
, which should be provided by the fbi
or fbida
package depending on your distribution. Note that it only works in real terminals (ttys).
Solution 5
By the way, i m always in the same situation, and I use mc (midnight commander) which handles text pdf's very well... Just view the file (F3) in mc
bitmask
I am a computer scientist, enthusiast programmer, and activist. Accept policy If you wonder why I didn't accept your answer, although it is obviously the right thing: Usually, I like to wait at least an hour before accepting anything, often I wait a day or so. More random information about me kernel: linux distro: debian interface: xmonad + mate text: vim web: firefox mail: thunderbird programming: mainly c++, some python, occasionally haskell, svg speak: de, en, es (read-only), limited support: fr, ru rcs: git scifi: The Matrix, Star Trek, Doctor Who, Firefly First to earn the the-matrix bronze badge on scifi.SE. Flair Bad Wolf
Updated on July 05, 2022Comments
-
bitmask almost 2 years
Hey, for quite a while now, I am looking for a pdf viewer for the command line.
As I like to work without X on Linux, and often work on a remote machine, I would like to have a tool to read pdfs. There are quite a lot of really good graphical programs (evince, okular, acroread, ...) to do the job, so I figured there should be at least one decent text-mode tool. But I don't even know of a crappy one!
Currently, I either start X only to read pdfs, or use pdftohtml+lynx. However, the latter does not produce a very good output, and most documents are just unreadable, especially if they contain mathematical formula.
Google is full of people saying either it's not possible or suggesting the pdftohtml version.
I realise, this is not exactly a programming question, but I am currently considering starting a project to implement such a program, unless there already is a good one out there.
Thanks for any suggestions.
-
bitmask over 13 yearsNeither of them works for my system, I tried tweaking the arguments but it did not display the text but a ps formatted file, and since I am not a printer ...
-
bitmask over 13 yearsThis is awesome! Although you have to be root, which I don't understand, but okay. Still awesome.
-
Kurt Pfeifle over 13 yearsD'oh! I mis-typed the command. Use
pdftotext
instead ofpdftops
... (I'll edit the answer to reflect this correction). -
Giacomo over 13 yearsCheck the permissions of the framebuffer device:
$ls -l /dev/fb0 crw-rw---- 1 root video ...
. You may need to be in thevideo
group in order to have user access to the framebuffer. -
Giacomo about 12 yearsNeat trick! On archlinux I had to install
lesspipe
for this to work, other distibutions may have it installed by default. +1 -
akhy about 11 yearsisn't pdf a binary format? The text produced by
less
should be garbled -
Abbafei about 11 yearsOn some systems (tested on Debian), the command
lesspipe <filename> | less
works. -
Abbafei about 11 yearsSimilarly,
pdftohtml
makes an HTML copy, which can be viewed with a text mode web browser, for examplew3m
orlinks
. -
shgnInc over 10 years@kasra None of the
less
andlesspip
didn't work for me on ubuntu12.04?? How to open the pdf files? -
Tatsh almost 10 yearsThe Ghostscript command works great and works a lot better than that stupid answer above that says to use less. This should be the highest rated answer.
-
Mike McMahon over 9 yearsFor people like me who found this and get the error "no pdftottext available" just
apt-get install pdftohtml
(or yum...etc depending on your distro) to get this to work. -
Frank Kusters about 9 years@akhyar: less automatically uses pdftotext to convert binary to text.
-
DrBeco over 8 yearsThis one here should be the accepted answer. More precisely,
pdftotext
to the job gracefully. Specially with-layout
. -
DrBeco over 8 yearsI would recommend look to the answer bellow that explains
pdftotext
tool. -
Felipe over 8 yearsUse
sudo apt-get install poppler-utils
if pdftohtml is not available. -
silvio about 6 yearsDownvoted, because the answer isn't complete. Its using tools behind other tools. lesspipe check the mimetype of the document and start a configured tool. If this is not configured, it will not work.
-
Shiplu Mokaddim over 4 yearsWhat? I have been in the Linux terminal for more than 14 years now. How come I never tried it?
-
fivestones over 3 yearsThis is the answer that will show you the pdf as it was designed to be seen, with the linux framebuffer, on the commandline. Specifically I have used jfbpdf with good success, and it appears to be in active development.
-
Fox over 3 years
less
not doing properly on my Linux it show broken texts that look like tryingcat binaryFile