Question

How can we read contents of the pdf file using vim command in the terminal? I have tried using pdftk by uncompressing it but still its not working for me. Is there any other way to decrypt or decode the pdf so that we can read by the terminal in any Linux flavour using vim.

Was it helpful?

Solution

If you want to read the pdf as text you can try the pdftotext command, though it won't always be beautiful. If you'd like vim to open pdf files in a pdf reader you can use something in your .vimrc like

au BufRead *.pdf sil exe "!xdg-open " . shellescape(expand("%:p")) | bd | let &ft=&ft | redraw!

OTHER TIPS

This question is more or less a duplicate of this one.
However, following the answers of @Conner and @Eric, the pdftotext utility is a recommended approach if you are only interested in the text content.

A possible approach to pdftotext can be found e.g. here.
There also exists a rather new Vim plugin to simplify these steps. This plugin can be found here or here

You might also write some ftplugin acting as a preprocessor to extract the text of a given pdf. Nevertheless, you won"t be able to change anything in the pdf with the proposed tools.

Some pdf text contents can be extracted with pdf2txt, then fed to vim. Of course, you will lose most of the formatting, graphics, etc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top