1

Newest EDIT

I think my question wasn't very clear, so I'm trying to put some details.

  1. With pdf-tools opening pdf files withing Emacs (PDFview buffers) works great. What I like is to get an org-link to a precise position (of the pointer on a page): Just a link that I can copy and paste into any org-file to use is it later to go directly (without activating org-noter) to that position.

    ("precise position": I'd like to get the x- and y-values of the pointer. But the y-value alone (scroll position) is ok.)

  2. The PDF file shouldn't be changed. Neither at producing the link nor at a later opening of the link (from an org file).

    I just need a temporary icon at the position, like the arrow in org-noter which you get with org-noter-sync-current-note.

    Unfortunately this function only works in an "org-noter buffer" and I need a "globally" valid link.


I often use in org-files pdf-links like this: [[pdf:~/book.pdf::5++2.13]] After clicking I get the pdf file buffer on the right page: 5. And PDFview seems to go to the right exact position at that page: I can see in status bar: 10% an when I change the y-value from 2.13 to 10.13 (5++10.13), I see 'Bot'(Bottom) there.

My problem is that I don't get any pointer/icon at that specific position. Any idea to solve it? Should I change some variables?

I've installed org-pdftools as described: https://github.com/fuxialexander/org-pdftools

Note: I don't have at that position a real annotation in the pdf file. So it's maybe not the default use of the link function.


EDIT: I've deleted my old code here, it was wrong.

2

SECOND EDIT (incl. 'main' answer)

As mentioned in the comments, this feature has already been implemented into org-pdftools. However, org-pdftools does insert a permanent text annotation, but I guess that is not too much of a problem for you.

To get it to work (currently, until https://github.com/fuxialexander/org-pdftools/pull/75 gets merged), just replace the org-pdftools-use-freestyle-annot with org-pdftools-use-freepointer-annot in the installation code as given in the org-pdftools README. Afterwards you can insert the pointer/text annotation using M-x org-noter-pdftools-insert-precise-note. The pointer is customizable also. Just do M-x customize-variable and type org pointer to find the relevant variables.

And just to come back to the translation of the y-position, you could translate it as follows, but it is probably not what you desire as it only represents the scrolling position:

 (defun my-pointer-function (orig-func &rest args)
  (apply orig-func args)
  (let ((height (round
                 (/
                  (*
                   (string-to-number (match-string 4 (car args)))
                   (cdr (pdf-view-image-size)))
                  (frame-char-height)))))
    (pdf-annot-add-text-annotation (cons 10 height) "Circle")))

(THIRD EDIT)

You could delete these pointers again for example when you are changing the page using e.g.:

(defvar my-pointers nil)

(add-hook 'pdf-view-before-change-page-hook #'pdf-pointer-delete-hook-function)

(defun pdf-pointer-delete-hook-function ()
  (while my-pointers
    (pdf-annot-delete (pop my-pointers))))

I am not sure about the robustness of this code, but you can modify/improve it whenever it seems not to work.

FIRST EDIT

It looks like, if you do not have pdf-tools installed (i.e. the feature available), then you can use org-pdftools-open-custom-open to define a custom function for opening the link.

However, this feature appears not to be available when you have pdf-tools installed. So then you could advise the function org-pdftools-open-pdftools, e.g. as follows:

(defun my-pointer-function (orig-func &rest args)
  (apply orig-func args)
  (pdf-annot-add-text-annotation '(100 . 200) "Circle")
  (print args))

(advice-add 'org-pdftools-open-pdftools :around #'my-pointer-function)

This advice (i.e. the my-pointer-function) will also print the args. I'll leave it to you to translate the args to some actual position where you would like to have the pointer inserted.

END EDIT

I guess there is no straightforward/default way to achieve this, because it is not possible to draw on .png images in Emacs.

If you still want it, then there are multiple hacks possible, of which probably the easiest option is to draw an icon (text annotation) with pdf-annot-add-text-annotation, e.g.: (pdf-annot-add-text-annotation '(100 . 200) "Circle").

To preview (or just for fun) the possible icons (in pdf-annot-standard-text-icons), you can evaluate the following lines in a pdf buffer:

(let ((pos 0))
  (dolist (type pdf-annot-standard-text-icons)
    (pdf-annot-add-text-annotation (cons pos 0) type)
    (setq pos (+ pos 100))))

These annotations will only get saved if you save the document. Or you could additionally add another hack to delete it again when you start scrolling, which should not be too difficult if you know some emacs-lisp.

9
  • I have pdf-tools installed: github.com/politza/pdf-tools. Or do you mean something else?
    – rl1
    Aug 9 at 14:41
  • Yes that is what I mean. So then, as I wrote, this answer (using the advice) should work for you. Also, I am not sure how you installed pdf-tools but you would probably prefer to use the maintained fork at github.com/vedang/pdf-tools Aug 9 at 14:56
  • I installed it with the internal function of emacs (list-packages) from melpa, and your link is the true one. Thanks for your help. It worked, also with the "translation" of the args. I've added the code to my answer. I hope it's ok.
    – rl1
    Aug 9 at 16:29
  • "Or you could additionally add another hack to delete it again when you start scrolling, which should not be too difficult if you know some emacs-lisp." I think this is too difficult for me.
    – rl1
    Aug 9 at 16:33
  • 1
    My friend tested it and it is working fine there also. So I am not sure how you copied the code. Anyway, stack-exchange warns here to avoid long discussions in the comment section, and it tells me we should be able to move to some chat somehow. Or otherwise you could visit the Spacemacs chat also, and I can help you debugging over there. But again, note that this only represents the y-scrolling position (vscroll). If you want to get a pointer at some exact location then you should use the feature that comes with org-(noter-)pdftools. Aug 9 at 20:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.