Configure doc-view-mode for Windows


doc-view-mode or DocView is a library that allows Emacs to open various types of documents: postscript, DVI, PDF and OpenOffice files. It works by converting those documents to images, which are displayed as pages in an Emacs buffer.

doc-view-mode is not very clever, and there are better alternatives, such as pdf-tools, for many of the file types. However, many of those alternatives do not with the stock version of Emacs for Windows, and DocView is a rather handy (and often faster) alternative to complex viewers, such as a LibreOffice text editor.

It is also interesting that DocView allows you to open PDF files in text-mode, using pdftotext to extract and format the body of the PDF. I use this as a starting point to convert minutes and reports to org-mode documents, for instance.

DocView on Windows

The default configuration for doc-view-mode assumes that certain utilities are around and accessible in the command line. That may be ok in some Linux systems, but it is not always the case on Windows.

One solution often suggested is to install msys, a Unix-like environment that provides many of the required tools. I prefer not to do this. Instead, I work with Scoop, a library that allows unpriviledged users to install programs in the Windows "home" directory. I use this library to install two pieces of software:

  • MikTeX, a LaTeX environment which comes with many handy tools, such as a copy of Ghostscript, a copy of Cairo for PDF conversion, etc.
  • LibreOffice, the free alternative to Microsoft Office, which is installed as portable application inside the scoop directory.
(use-package doc-view
  :defer t
  ;; Use MikTeX's utilities for PDF conversion and searching
  (doc-view-ghostscript-program "mgs.exe")
  (doc-view-pdf->png-converter-function 'doc-view-pdf->png-converter-ghostscript)
  (doc-view-pdftotext-program "miktex-pdftotext.exe")
  ;; MikTeX's utilities also for vieweing DVI files
  (doc-view-dvipdfm-program "dvipdfm.exe")
  ;; I install Libreoffice using Scoop as a portable, standalone
  ;; executable. This is the location of the utility within there.
  (doc-view-odf->pdf-converter-program "~/scoop/apps/libreoffice-stable/current/App/libreoffice/program/soffice.exe")
  (doc-view-odf->pdf-converter-function 'doc-view-odf->pdf-converter-soffice)

Overall, this works very well. With minor tweaks, this configuration can be extended to use doc-view-mode as viewer of mail attachments in Gnus