可以指定一个指向特定页面的 PDF 的 URI 吗?

huangapple go评论64阅读模式
英文:

Is it possible to specify a URI to a pdf that points to a specific page?

问题

我对Windows特别感兴趣,但关于不同操作系统的回答也很有趣。

据我所知,在URL中,可以通过添加#page=<页码>字段来指示特定的PDF页面。根据URI规范,应该可以使用字段(使用#<字段>语法)和查询(使用?<键>=<值>语法)。然而,形式为file:///path_to_document.pdf#page=20file:///path_to_document.pdf?page=20的URI对我来说不起作用,Windows将整个字符串解释为路径,然后无法找到它。

有没有办法实现这个?我在网上找不到任何信息。

英文:

I'm specifically curious about Windows, but answers about different OS are interesting too.

Afaik in URLs a specific PDF page can be indicated by adding a #page=&lt;page number&gt; field. According to the URI specification, fields (using the #&lt;field&gt; syntax) and queries (using the ?&lt;key&gt;=&lt;value&gt; syntax) should be possible. However, URIs of the form file:///path_to_document.pdf#page=20 or file:///path_to_document.pdf?page=20 didn't work for me, Windows is interpreting the whole string as a path, which it then can't find.

Is there any way to accomplish this? I couldn't find anything online.

答案1

得分: 1

以下是您提供的内容的翻译部分:

当从操作系统调用文件时,存在基于系统的规则。因此,从操作系统调用文件需要一定的语法,对于某些字符需要引号,以便它们能够正常工作,无论默认的 PDF 处理程序是什么:-
可以指定一个指向特定页面的 PDF 的 URI 吗?

默认的处理程序可能包括不同的页面切换语法,比如 exe -page ## 文件名。

可以指定一个指向特定页面的 PDF 的 URI 吗?

当使用 URL 时,需要一个 URL 处理程序,因此这将在 Windows 中起作用

&quot;C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe&quot; &quot;file:///C:/Apps/PDF/poppler/%2333.pdf#page=20&quot;

URL 可能位于 LAN 服务器上,而 Windows 通常会对 \ 和 / 的使用进行调整,但不一定都接受两者。因此,规则是“使用引号”并将系统标点替换为安全字符,并确保“记住上次的页码”未激活。

可以指定一个指向特定页面的 PDF 的 URI 吗?

使用 # 片段进行 PDF 导航是由 Adobe 为其 Acrobat 插件引入的,并已被一些浏览器插件部分采用。因此,在 Chrome 中有些方式可以正常工作,但在 FireFox 中可能具有不同的名称或行为,因此请小心选择默认浏览器。

一个示例是 #search= 在 FireFox 中运行良好,但在 Chromium 中完全不同。#:~:text=Chromium 但不适用于 PDF 或此页面!

在评论中,您提到 Obsidian 是一个封闭的产品(不支持轻松修改)。我发现它需要每个链接一个对象,因此在库中,您需要使用一个 window.lnk 文件作为从内部到外部的调用中间件

可以指定一个指向特定页面的 PDF 的 URI 吗?

在库中,它可能是

Open 3pages.pdf @ page 2 [page 2 of 3Pages.pdf](file:///C:%5CApps%5CPIM%5CObsidian%5C3Pages.pdf%20-%20Shortcut.lnk)

在外部,快捷方式可能是

&quot;C:\Program Files\SumatraPDF\SumatraPDF.exe&quot; -page 2 C:\Apps\PIM\Obsidian\vault\3Pages.pdf

当我测试这种解决方法时,每个链接将占用大约 4KB 的磁盘空间,因此可能有更好的方法来调用带有 2 个参数的文件,这在许多情况下可以作为“中间件”工作,但也有开源插件,也许足够接近以适应,参见 https://github.com/MichalBures/obsidian-file-path-to-uri

英文:

When calling files from the Operating System there are rules that are system based. So calling a file from OS needs a certain syntax, that needs quoting for some characters, so these work, whatever the default PDF handler may be:-
可以指定一个指向特定页面的 PDF 的 URI 吗?

That default handler may include a different page switch syntax such as exe -page ## filename.

可以指定一个指向特定页面的 PDF 的 URI 吗?

When using a URL you need a URL handler, so this will work in Windows

&quot;C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe&quot; &quot;file:///C:/Apps/PDF/poppler/%2333.pdf#page=20&quot;

The URL can be on a LAN server and windows will often fiddle with the usage of \ and / but not aways accept both. So the rule is "use quotes" AND replace system punctuation with safe characters AND ensure "Remember last page" is not active.

可以指定一个指向特定页面的 PDF 的 URI 吗?

The use of # fragments for PDF navigation was introduced by Adobe for their Acrobat plug-in and has in parts been adopted by some browser plug-ins . So some work one way in Chrome but some can be different name or behaviour in FireFox, so beware which browser you use as default.

One example is #search= works well in FireFox but is totally different in Chromium. #:~:text=Chromium but does not work with PDF nor this page !

In comments you mentioned Obsidian which is a closed product (not open source for easy modifications). What I found is it need an object per link thus in the vault you would need to use a window.lnk file as the shim from internal to external calling

可以指定一个指向特定页面的 PDF 的 URI 吗?

in the vault it would be

Open 3pages.pdf @ page 2 [page 2 of 3Pages.pdf](file:///C:%5CApps%5CPIM%5CObsidian%5C3Pages.pdf%20-%20Shortcut.lnk)

externally the shortcut could be

&quot;C:\Program Files\SumatraPDF\SumatraPDF.exe&quot; -page 2 C:\Apps\PIM\Obsidian\vaultPages.pdf

As I tested this workaround each link would be a highly wasteful 4Kb of disk space, so there are perhaps better ways to call 1 file with 2 arguments, which works in many cases as a "Shim", however there are open source plug-ins that are perhaps close enough to adapt see https://github.com/MichalBures/obsidian-file-path-to-uri

huangapple
  • 本文由 发表于 2023年2月8日 23:17:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387882.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定