No edit summary |
(Change <tt> to <code>, perhaps also minor tweak.) |
||
(10 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
+ | {{TipImported |
||
− | {{review}} |
||
− | {{Tip |
||
|id=1356 |
|id=1356 |
||
+ | |previous=1354 |
||
− | |title=Viewing PDF files in VIM |
||
+ | |next=1359 |
||
− | |created= |
+ | |created=2006 |
|complexity=basic |
|complexity=basic |
||
− | |author= |
+ | |author= |
− | |version= |
+ | |version=7.0 |
|rating=41/26 |
|rating=41/26 |
||
+ | |category1= |
||
− | |text= |
||
+ | |category2= |
||
− | Inspired by the excellent [[VimTip790]], here's how to view PDF files in VIM. |
||
− | |||
− | |||
− | |||
− | Get the free Xpdf from (http://www.foolabs.com/xpdf/download.html). For Win32 specifically, you can get the zip file and just extract pstopedf.exe. |
||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
− | autocmd BufReadPre *.pdf set ro |
||
− | |||
− | autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" - |
||
− | |||
− | |||
− | |||
− | And that's it! And just like for MS-Word files, this allows you to use VIM to diff two pdf files very nicely. |
||
}} |
}} |
||
+ | This tip shows how to use Vim to view the text in a PDF document. That can be useful to use Vim to see the differences between the text in two versions of a pdf. You need to install [http://www.foolabs.com/xpdf/ xpdf] (available on all major platforms) as it provides the <code>pdftotext</code> utility to read the text from a pdf file. |
||
− | == |
+ | ==Procedure== |
⚫ | |||
− | Oops! Of course I meant "just extract pdftotext.exe"... |
||
+ | <pre> |
||
− | |||
+ | :command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> - |
||
− | Erez Volk |
||
⚫ | |||
− | , October 8, 2006 5:58 |
||
+ | </pre> |
||
− | ---- |
||
− | If you happen to be on UNIX or have the fmt utility, a slight improvement is: |
||
− | autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" - |fmt -cw78 |
||
− | |||
− | '''Anonymous''' |
||
− | , October 8, 2006 6:17 |
||
− | ---- |
||
− | Or, better still, |
||
− | autocmd BufReadPost *.pdf %!pdftotext -nopgbrk "%" - |fmt -csw78 |
||
− | |||
− | '''Anonymous''' |
||
− | , October 8, 2006 6:28 |
||
− | ---- |
||
− | Add silent and you dont need to press enter |
||
⚫ | |||
− | |||
− | kaz.rag--AT--gmail.com |
||
− | , October 8, 2006 18:29 |
||
− | ---- |
||
− | Win32 Users, |
||
− | |||
− | pdftotext comes as part of the CygWin Suite http://www.cygwin.com/ |
||
− | |||
− | |||
− | |||
− | http://successtheory.com |
||
− | , October 10, 2006 7:53 |
||
− | ---- |
||
− | Very nice! Thanks :-) |
||
− | |||
− | hans-peter--AT--prenzel.de |
||
− | , October 16, 2006 9:37 |
||
− | ---- |
||
− | Nice, but should it be wrote in .vimrc. What is difference b/w .vimrc and .exrc file? |
||
− | |||
− | gururaj.jois--AT--yahoo.co.in |
||
− | , October 16, 2006 23:02 |
||
− | ---- |
||
− | Debian packages: poppler-utils for the cool kids, xpdf-utils for the old-skool. |
||
− | |||
− | Tobu |
||
− | , October 22, 2006 17:29 |
||
− | ---- |
||
− | You may want to call pdftotext with parameter -layout -- tries to maintain the original layout of pages. This don't compress all the page into |
||
− | one chunk of text. |
||
+ | These define the <code>:Rpdf</code> command to read the result of converting a pdf document to text. The text is read into the current buffer after the current line. The first reads the pdf with each paragraph as a long line, while the second wraps long lines (if the <code>fmt</code> utility is available). |
||
− | '''Anonymous''' |
||
− | , November 10, 2006 10:20 |
||
− | ---- |
||
− | >Win32 Users, |
||
− | >pdftotext comes as part of the CygWin Suite http://www.cygwin.com/ |
||
− | *rollseyes* |
||
+ | For example, the following commands open a new tab page and read the text from a pdf document into the buffer. |
||
− | Please don't install cygwin just fpr pdftotext. Use the link to the xpdf-files, as the author suggests. There is a pdftotext for Win32 as well... |
||
+ | <pre> |
||
+ | :tabnew |
||
+ | :Rpdf example.pdf |
||
+ | </pre> |
||
+ | ==See also== |
||
+ | *[[VimTip790|View and diff MS Word files]] Uses a similar concept to open Word documents. |
||
+ | *[[VimTip667|Working with CSV files]] Uses a similar concept to open Excel spreadsheets. |
||
+ | ==Comments== |
||
− | '''Anonymous''' |
||
− | , December 10, 2006 11:15 |
||
− | ---- |
||
− | <!-- parsed by vimtips.py in 0.569180 seconds--> |
Revision as of 06:22, 13 July 2012
This tip shows how to use Vim to view the text in a PDF document. That can be useful to use Vim to see the differences between the text in two versions of a pdf. You need to install xpdf (available on all major platforms) as it provides the pdftotext
utility to read the text from a pdf file.
Procedure
Put one of the following mappings in your vimrc:
:command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> - :command! -complete=file -nargs=1 Rpdf :r !pdftotext -nopgbrk <q-args> - |fmt -csw78
These define the :Rpdf
command to read the result of converting a pdf document to text. The text is read into the current buffer after the current line. The first reads the pdf with each paragraph as a long line, while the second wraps long lines (if the fmt
utility is available).
For example, the following commands open a new tab page and read the text from a pdf document into the buffer.
:tabnew :Rpdf example.pdf
See also
- View and diff MS Word files Uses a similar concept to open Word documents.
- Working with CSV files Uses a similar concept to open Excel spreadsheets.