emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Georges Ko <gko@gko.net>
To: emacs-orgmode@gnu.org
Subject: Link to open PDF at a specific page
Date: Sat, 14 Nov 2020 16:46:24 +0800	[thread overview]
Message-ID: <yqc2amtzkuxzz.fsf@gko.net> (raw)


I'd like to open a PDF file to a specific page from a link, using the
default PDF viewer in Windows (same as w32-shell-execute "open"), which
opens a browser.

With a browser, I can open it with this HTML link:

  <a href="file:///c:/a/b/c/file.pdf#page=4">Page 4</a>

This link as an Org mode link doesn't work:


as "#page=4" is interpreted as part of the filename by w32-shell-execute.

If I modify org-file-apps for PDF to:

("\\.pdf::\\([0-9]+\\)\\'" . "browser file:///%s#page=%1")

and if the Org link is:


it doesn't work because the argument passed to browser is:


A quick workaround is to modify org-open-file by removing
shell-quote-argument, from:

  (shell-quote-argument (convert-standard-filename file))


  (convert-standard-filename file)

to get the following string, which correctly opens page 4.


If I export the file as HTML, it is output as:

  <a href="file:///c:/a/b/c/file.pdf#MissingReference">...</a>

so I modified org-html-link from:

  (concat raw-path
	  (org-publish-resolve-external-link option path t))


  (concat raw-path
	  (let ((r (org-publish-resolve-external-link option path t)))
	    (or (and (string= r "MissingReference")
		     (string-match "\\.pdf\\'" path)
		     (string-match "[0-9]+" option)
		     (format "page=%s" option))

which generates the wanted HTML link:

  <a href="file:///c:/a/b/c/file.pdf#page=4">...</a>

Is there any way less quick & dirty to achieve this?


             reply	other threads:[~2020-11-14  8:47 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-14  8:46 Georges Ko [this message]
2020-11-14 11:34 ` Link to open PDF at a specific page Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=yqc2amtzkuxzz.fsf@gko.net \
    --to=gko@gko.net \
    --cc=emacs-orgmode@gnu.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).