├── LICENSE ├── README.md ├── demo.gif ├── doc └── vim-pdf.txt └── plugin └── vim-pdf.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Junhee Lee 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # vim-pdf 2 | 3 | ![demo](demo.gif) 4 | 5 | **vim-pdf** helps VIM to read PDF files in text format using pdftotext utility. 6 | 7 | ## Prerequisite 8 | 9 | 10 | * poppler 11 | ``` 12 | sudo apt install poppler-utils 13 | sudo apt install libpoppler-cpp-dev 14 | ``` 15 | * pdftotext 16 | 17 | ``` 18 | 19 | pip install pdftotext 20 | 21 | ``` 22 | ## Installation 23 | 24 | it's recommended that you use a plugin manager like [vim-plug](https://github.com/junegunn/vim-plug) 25 | 26 | ### vim-plug 27 | 28 | ``` 29 | Plug 'makerj/vim-pdf' 30 | ``` 31 | 32 | ### Vundle 33 | 34 | ``` 35 | Plugin 'makerj/vim-pdf' 36 | ``` 37 | 38 | 39 | ## Usage 40 | 41 | Just open the PDF file. The rest is done by vim-plug. 42 | 43 | -------------------------------------------------------------------------------- /demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/makerj/vim-pdf/24996488c0a5a3404ec72d125a17ded7832f5f3e/demo.gif -------------------------------------------------------------------------------- /doc/vim-pdf.txt: -------------------------------------------------------------------------------- 1 | *vim-pdf.txt* vim-pdf 2 | 3 | vim-pdf helps VIM to read PDF files in text format using pdftotext utility. 4 | -------------------------------------------------------------------------------- /plugin/vim-pdf.vim: -------------------------------------------------------------------------------- 1 | "Let vim as a pdf reader 2 | if exists("g:vim_pdf_loaded") 3 | finish 4 | endif 5 | let g:vim_pdf_loaded = 1 6 | 7 | let s:pdf_cache = {} 8 | autocmd BufReadPost *.pdf call s:loadpdf() 9 | autocmd BufLeave *.pdf setlocal write 10 | function s:loadpdf() 11 | if (line('$') < 2 || !strpart(getline(1), 1, 3) ==# "PDF") 12 | echo "vim-pdf: not a valid pdf file. stop converting..." 13 | return 14 | endif 15 | if !executable("pdftotext") 16 | echo "vim-pdf: pdftotext is not found. stop converting..." 17 | return 18 | endif 19 | 20 | execute "silent %delete" 21 | if has_key(s:pdf_cache, @%) 22 | execute "silent '[-1read ".s:pdf_cache[@%] 23 | else 24 | let pdf = escape(expand(@%), "'") 25 | let pdf_cache = escape(tempname(), "'") 26 | call system("pdftotext -nopgbrk -layout ". 27 | \"'".pdf."' ". 28 | \"'".pdf_cache."'") 29 | execute "silent '[-1read ".pdf_cache 30 | let s:pdf_cache[@%] = pdf_cache 31 | endif 32 | 33 | execute "silent setlocal nowrite" 34 | execute "silent set filetype=text" 35 | endfunction 36 | --------------------------------------------------------------------------------