How to open Org mode hyperlinks at specific page number with qpdfview?

This explains how to set Org mode to open specific page of any PDF file or PDF file without designated specific page by using qpdfview.

Here is my variable org-file-apps where I have set 2 regular expressions, one is for files with the page with separator :: and one is for plain PDF files without designated page number:

org-file-apps ⇒ (("\\.pdf::\\([0-9]+\\)\\'" lambda (file link) (my-qpdfview file link)) 
                 ("\\.pdf\\'" lambda (file link) (my-qpdfview file link)) 
         (auto-mode . emacs) 
         ("\\.mm\\'" . default) 
         ("\\.x?html?\\'" . default))

And here is the function:

(defun my-qpdfview (file link)
  (if (string-match "[\\.pdf|::[:digit:]]$" link)
      (let* ((extension (file-name-extension link))
         (page (string-match "::" extension))
         (page (if page (progn (substring extension (+ 2 (string-match "::" extension))))))
         (file-argument (if page (format "%s#%s" file page) file)))
    (call-process "qpdfview" nil nil nil file-argument))))

This hyperlink below works well, and opens qpdfview at specific page number #4.

[[file:~/pllong.pdf::4][test page #4]]

And this below works as well, and opens the PDF file:

[[file:~/pllong.pdf][test page]]

Related hyperdocument tags

org-mode qpdfview specific-page pdf emacs emacs-lisp

GNU General Public License Version 3

Copyright © 2021-05-12 22:39:58+02 Jean Marc Louis

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.