CLI pdf viewer for linux

64,840

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

http://web.archive.org/web/20150316143120/http://linuxers.org/howto/how-open-pdf-files-linux-console-using-fbgs-framebuffer-pdf-viewer

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

Share:
64,840
bitmask
Author by

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, 2022

Comments

  • bitmask
    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
    bitmask over 13 years
    Neither 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
    bitmask over 13 years
    This is awesome! Although you have to be root, which I don't understand, but okay. Still awesome.
  • Kurt Pfeifle
    Kurt Pfeifle over 13 years
    D'oh! I mis-typed the command. Use pdftotext instead of pdftops... (I'll edit the answer to reflect this correction).
  • Giacomo
    Giacomo over 13 years
    Check the permissions of the framebuffer device: $ls -l /dev/fb0 crw-rw---- 1 root video .... You may need to be in the video group in order to have user access to the framebuffer.
  • Giacomo
    Giacomo about 12 years
    Neat trick! On archlinux I had to install lesspipe for this to work, other distibutions may have it installed by default. +1
  • akhy
    akhy about 11 years
    isn't pdf a binary format? The text produced by less should be garbled
  • Abbafei
    Abbafei about 11 years
    On some systems (tested on Debian), the command lesspipe <filename> | less works.
  • Abbafei
    Abbafei about 11 years
    Similarly, pdftohtml makes an HTML copy, which can be viewed with a text mode web browser, for example w3m or links .
  • shgnInc
    shgnInc over 10 years
    @kasra None of the less and lesspip didn't work for me on ubuntu12.04?? How to open the pdf files?
  • Tatsh
    Tatsh almost 10 years
    The 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
    Mike McMahon over 9 years
    For 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
    Frank Kusters about 9 years
    @akhyar: less automatically uses pdftotext to convert binary to text.
  • DrBeco
    DrBeco over 8 years
    This one here should be the accepted answer. More precisely, pdftotext to the job gracefully. Specially with -layout.
  • DrBeco
    DrBeco over 8 years
    I would recommend look to the answer bellow that explains pdftotext tool.
  • Felipe
    Felipe over 8 years
    Use sudo apt-get install poppler-utils if pdftohtml is not available.
  • silvio
    silvio about 6 years
    Downvoted, 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
    Shiplu Mokaddim over 4 years
    What? I have been in the Linux terminal for more than 14 years now. How come I never tried it?
  • fivestones
    fivestones over 3 years
    This 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
    Fox over 3 years
    less not doing properly on my Linux it show broken texts that look like trying cat binaryFile