1

I want to write a simple function that "turns the pages" in pdf-view-mode. If I'm reading a file with one book page per pdf page that's simple: pdf-view-next-page plus image-scroll-down (to get me to the top of the page, assuming it's cropped).

But if each pdf page is a scan of two book pages side by side, the function should check if the image is cropped and I'm looking at the bottom left region (the lower part of the left page), and in that case move me to the top right part of the image. If instead I'm looking at the bottom right, it will move me to the top left of the next image.

In order to do that I need to know:

  1. how to refer to the image that is currently being displayed in pdf-view-mode
  2. how to check its size to see if it's wider than it is tall (image-size should be the function, but I don't know on what to call it)
  3. how to get the position of the current crop region
1

1 Answer 1

1

EDIT: Fixed the function to use pixels instead of characters as unit of measure, otherwise the check of the page ratio would be meaningless.

I asked chatgpt and after some hallucinations I got something usable:

  1. how to refer to the image: (image-get-display-property)
  2. getting the image size: (image-size (image-get-display-property))
  3. getting the part of the page I'm looking at: (window-inside-edges) to get the dimensions of the window, (window-vscroll) and (window-hscroll) to get how much I scrolled from the top left corner.

And here's the function I've written, that seems to work as desired in the first tests:

(defun my-pdf-pageturner () (interactive) (let* ( (pagesize (image-size (image-get-display-property) t )) (winsize (cons (window-body-width nil t) (window-body-height nil t) )) (scrollsize (cons (- (car pagesize) (car winsize)) (- (cdr pagesize) (cdr winsize)))) (vscroll (window-vscroll nil t )) (hscroll (* (window-hscroll) (frame-char-width))) ) (if (< (cdr pagesize) (car pagesize) ) (if (< vscroll (/ (cdr scrollsize) 2)) (image-scroll-up) (if (> vscroll (/ (cdr scrollsize) 2)) (if (< hscroll (/ (car scrollsize) 2)) (progn (image-scroll-down) (image-scroll-left)) (if (> hscroll (/ (car scrollsize) 2 )) (progn (pdf-view-next-page) (image-scroll-down) (image-scroll-right)))))) (if (< vscroll (/ (cdr scrollsize) 2)) (image-scroll-up) (progn (pdf-view-next-page) (image-scroll-down))) ) )) 

Turns out that vscroll accepts an argument to give its output in pixels: (window-vscroll nil t); hscroll does not so I have to calculate it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.