6

I have a document displayed in a doc-view buffer. However, the document is rotated 90 degrees left. Can I rotate a doc in emacs doc-view?

Jeff Bauer
  • 13,890
  • 9
  • 51
  • 73
Dervin Thunk
  • 19,515
  • 28
  • 127
  • 217

1 Answers1

11

I also had this requirement. Sadly doc-view doesn't provide this functionality.

Also the image code used by emacs can't rotate images. So I created a function which utilizes ImageMagick to transform the png files stored in the cache dir and redisplay the current page:

(defun doc-view-rotate-current-page ()
  "Rotate the current page by 90 degrees.  Requires ImageMagick installation"
  (interactive)
  (when (eq major-mode 'doc-view-mode)
    ;; we are assuming current doc-view internals about cache-names
    (let ((file-name (expand-file-name (format "page-%d.png" (doc-view-current-page)) (doc-view--current-cache-dir))))
      ;; assume imagemagick is installed and rotate file in-place and redisplay buffer
      (call-process-shell-command "convert" nil nil nil "-rotate" "90" (concat "\"" file-name "\"") (concat "\"" file-name "\""))
      (clear-image-cache)
      (doc-view-goto-page (doc-view-current-page))))))
killdash9
  • 2,314
  • 2
  • 23
  • 17
Jürgen Hötzel
  • 18,997
  • 3
  • 42
  • 58
  • I just noticed that my edit contains a superfluous paren at the end. S.O. will not allow me to make a one character edit to fix it. – killdash9 Mar 11 '15 at 21:32