View documents (PDF/PostScript/DVI) inside Emacs

Posted: August 22, 2007 in Emacs
Tags: , , , ,

Today I wrote an extension for emacs that lets you view pdf, ps or dvi documents in emacs. It’s named doc-view.el and I posted it to the emacs-sources mailing list (here it is). But I recommend that you get the latest version by cloning my Git repository.

A description of doc-view.el and how to get it can be found on my homepage.

UPDATE: doc-view is official part of Emacs and the default viewer for DVI and PDF files.

Advertisements
Comments
  1. gnugalaxy says:

    Wow, cool! I’ve been learning and learning elisp for so long that I didn’t learn at all hehe.. But here, you have done it! nice :) I’ll use it and come back.

  2. Tassilo Horn says:

    Thanks a lot for the compliments!

    Bye,
    Tassilo

  3. Pablo says:

    Great add-on :)
    ive been using it for a while and im missing only one thing. Rescaling images. Sometimes the pdf doc’s don’t fit in the window.

    Pablo

  4. Tassilo Horn says:

    With the doc-view version in Emacs CVS (23), you can enlarge and shrink the doc with + and -.

  5. This is very nice. I’ve been thinking of writing a similar reader that uses pdftotext for emacs buffer viewing, although there are obvious limitations. It would be nice to see a mode that allows options for conversion to text, tex, and png. The problem with png is that the file is no longer searchable. Maybe one day there will be a conkeroresque pdf viewer ;)

    • Tassilo Horn says:

      Hey Fred,
      doc-view allows both conversion to text (simply hit C-c C-t when viewing the doc as PNG images), and searching (C-s and C-r, mimicing the isearch behavior).
      Bye,
      Tassilo

  6. AC says:

    C-c C-t does not show the document source – it just shows document text (which is frustrating). How can I fix disable doc-view.el so I can actually see the pdf document source?

  7. Jeff Martens says:

    Can I disable DocView altogether? It’s inconvenient to have to manually switch to fundamental-mode every time I need to look at the beginning of a PDF.

    With Doc files I’m much more interested in hexlify-buffer than rendering. I have other tools to do that. Thanks!

    • Tassilo Horn says:

      Sure, simply remove its entry from auto-mode-alist:

      (setq auto-mode-alist
      (remove '("\\.\\(?:PDF\\|DVI\\|OD[FGPST]\\|DOCX?\\|XLSX?\\|PPTX?\\|pdf\\|dvi\\|od[fgpst]\\|docx?\\|xlsx?\\|pptx?\\)\\'" . doc-view-mode-maybe)
      auto-mode-alist))

      However, if you generally want to see pdf files and other docs in a hex editor, then I’d just add a new (overriding) entry that enables emacs’ hex editor (hexl-mode):

      (add-to-list 'auto-mode-alist
      '("\\.\\(?:PDF\\|DVI\\|DOCX?\\|XLSX?\\|PPTX?\\|pdf\\|dvi\\|docx?\\|xlsx?\\|pptx?\\)\\'" . hexl-mode))

      Bye,
      Tassilo

  8. Arjun Singh says:

    I am using emacs 24.2 version. I have some books saved in pdf format and i want to view them in emacs. Would you please explain by step-by-step instructions how i can view those books. I am fairly new to emacs so while explaining please mind a beginners point of view.

    • Tassilo Horn says:

      Emacs 24.2 has doc-view included. So the only thing you need to do is opening the book you want to read, i.e., C-x C-f ~/path/to/book.pdf.

      However, doc-view needs some external tools you need to have installed. Most importantly, you need either ghostscript or mupdf. (It might be that mupdf support is new in Emacs 24.3.)

      Also, your Emacs needs to be compiled with PNG support. If you’re on GNU/Linux, this should be the default. On windows, you might need to install libpng. Check out FAQ 3.3 in the emacs docs: http://www.gnu.org/software/emacs/windows/big.html

  9. vinhdizzo says:

    Hi Tassilo,

    I too am having issues with rendering pdf files using doc view on windows. I downloaded emacs 24.3 windows binaries, have ghostscript installed via cygwin (M-! gs confirms gs works), and placed libpng dll in my emacs/bin directory (and installed via the setup). I’ve also installed these libraries using cygwin. When I open an actual png file, the image also does not render. I get this message: “Cannot display image: (Invalid image specification)”.

    Would appreciate if you could guide me to getting this to work on windows. I really need to get back to being able to open frequent files using emacs bookmarks…

    Thanks so much!

  10. jochenhayek says:

    Hi, Tassilo,

    would you please have a look at http://www.emacswiki.org/emacs/DocViewMode and correct or remove the weird things?

    That would be so nice of you :-)

    Kind regards,
    Jochen

    • tsdh says:

      Sorry, no time to keep on updating non-official documentation. But basically the page is ok except that the broken link to my former homepage should be deleted. doc-view.el is included in emacs >= 23, and that’s the only reasonable way to get it.

  11. Armor Brabant says:

    doc-view is a pain in the backside. Sorry. I want to view pdf, ps, djvu, etc files in external applications specifically designed for their display, and I have to spend most of my time on emacs switching off and/or disabling doc-view.

    • tsdh says:

      What a constructive comment! Here are some notes:

      1. Disabling doc-view is a one-time effort, so I can’t see how you’ve spent most of your time doing that.
      2. When you want to view documents using external applications, then why do you open them in emacs in the first place?

      • Jeff Martens says:

        PDF and PS are text, emacs is a text editor, and when I open a text file I want to see the text. Other tools are fine for rendering, and can easily be launched from within emacs. Sometimes I teach image file formats, and it’s convenient to look at the bytes; hexlify-buffer is perfect for this. Emacs has always been the best tool, IMHO, for these things. IMHO, doc-view is a major departure from emacs’s use as a text or programmer’s editor. OTOH, in the ’80s and ’90s the kitchen sink as the emacs icon suggested that if you can put it in, put it in.

        Having said that, it seems doc-view is more popular than unpopular, and Tassilo responded to me quickly with simple instructions to disable it (see comments above, December 2011). How to disable it is google-able now, though it should be in the emacs wiki and other emacs documentation. I think we should just accept it, disable it, teach others how to disable doc-view, and move on.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s