Wikia

Vim Tips Wiki

Changes: Open PDF files

Edit

Back to page

(Replace with commands that I put on the talk page in response to a question in August 2011. The previous method was very complex and inefficient.)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
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 <tt>pdftotext</tt> utility to read the text from a pdf file.
+
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==
 
==Procedure==
Line 20: Line 20:
 
</pre>
 
</pre>
   
These define the <tt>:Rpdf</tt> 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 <tt>fmt</tt> utility is available).
+
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).
   
 
For example, the following commands open a new tab page and read the text from a pdf document into the buffer.
 
For example, the following commands open a new tab page and read the text from a pdf document into the buffer.

Latest revision as of 06:22, July 13, 2012

Tip 1356 Printable Monobook Previous Next

created 2006 · complexity basic · version 7.0


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.

ProcedureEdit

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 alsoEdit

CommentsEdit

Around Wikia's network

Random Wiki