emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Link to open PDF at a specific page
@ 2020-11-14  8:46 Georges Ko
  2020-11-14 11:34 ` Jean Louis
  0 siblings, 1 reply; 2+ messages in thread
From: Georges Ko @ 2020-11-14  8:46 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

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:

  file:///c:/a/b/c/file.pdf#page=4

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:

  file:///c:/a/b/c/file.pdf::4

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

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

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

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

to

  (convert-standard-filename file)

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

  "file:///c:/a/b/c/file.pdf#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))

to

  (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))
		r)))

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?

Thanks!





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Link to open PDF at a specific page
  2020-11-14  8:46 Link to open PDF at a specific page Georges Ko
@ 2020-11-14 11:34 ` Jean Louis
  0 siblings, 0 replies; 2+ messages in thread
From: Jean Louis @ 2020-11-14 11:34 UTC (permalink / raw)
  To: Georges Ko; +Cc: emacs-orgmode

* Georges Ko <gko@gko.net> [2020-11-14 11:48]:
> 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))
> 
> to
> 
>   (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))
> 		r)))
> 
> 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?

General function in plan Org program files shall not be modified in
the main development branch to serve a specific PDF reader on specific
OS system as that is hard coding and there are many PDF readers which
all behave in different manner.

Instead it is better if you make your custom link for Org that does
what you want.

It looks as being possible to be customized by using
org-link-abbrev-alist

Is it?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-11-16 10:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-14  8:46 Link to open PDF at a specific page Georges Ko
2020-11-14 11:34 ` Jean Louis

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

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).