I'm trying to control paging of a PDF file in doc-view mode. Say we have the following snippet

(let ((origin-frame (window-frame)))
  (with-selected-frame (make-frame-command)
    (let ((pdf-buffer (find-file "./test.pdf")))
      (set-window-buffer (get-buffer-window) pdf-buffer)
      (select-frame-set-input-focus origin-frame)
      (with-current-buffer pdf-buffer
        (doc-view-goto-page 5)))))

we make a new frame the display the pdf buffer then go back to our origin frame and try to scroll the pdf buffer to page 5 in the origin buffer.

eval the snippet, we can see the pdf buffer is actually displaying the content page 5, while the mode line says P1/12 DocView.(Note that the first time you open the pdf it may take some time to convert the pdf and causes the snippet fail) Switch to the pdf buffer and press n which calls doc-view-next-page, we can see the buffer goes to page 2.

That is to say, the buffer is not really went to page 5 just now but its 'content display' did. Using doc-view-goto-page in the pdf buffer will not have this problem as the modeling says P5/12 DocView after evaluation.

How to fix this? Is with-current-buffer not the way to go here? Thanks in advance!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.