I use pdf-tools to read PDFs inside of Emacs and greatly prefer it to DocView. I just noticed that when I try to open a URL thar points to a PDF in eww, it uses DocView instead of the pdf-view-mode from pdf-tools. This is particularly annoying since DocView fails to display the PDF! Switching the buffer to pdf-view-mode manually then succesfully shows it. Can I configure things so that eww uses pdf-view-mode on the first try?
Warning: dirty work-around ahead
Since you "greatly prefer [pdf-tools] to DocView", is it safe to assume that using it to view all pdfs is acceptable?
The following code snippet will switch the document to
doc-viewis entered with a
(defvar tv/prefer-pdf-tools (fboundp 'pdf-view-mode)) (defun tv/start-pdf-tools-if-pdf () (when (and tv/prefer-pdf-tools (eq doc-view-doc-type 'pdf)) (pdf-view-mode))) (add-hook 'doc-view-mode-hook 'tv/start-pdf-tools-if-pdf)
The behavior can be enabled or disabled by
setq-ing the variable
tv/prefer-pdf-tools to t or nil.
You can use an advise around
eww-display-pdf to override the definition of
doc-view-mode temporarily. With the new
nadvice library this is as easy as:
(advice-add 'eww-display-pdf :around (lambda (orig &rest args) (cl-letf (((symbol-function 'doc-view-mode) #'pdf-view-mode)) (apply orig args))) '((name . eww-display-pdf-tools)))
To revert back to the original
(advice-remove 'eww-display-pdf 'eww-display-pdf-tools).
I have opened Emacs bug 19270 to make the EWW PDF Mode customizable.