使用URL参数链接到PDF中的书签是否可行?

84

当在网站上提供PDF文件的链接时,是否可以在URL(请求参数)中包含信息,使得如果使用PDF浏览器插件,它可以跳转到特定的书签而不仅是打开文档的开始部分?

类似于:http://www.somehost.com/user-guide.pdf?bookmark=chapter3

如果不能使用书签,是否可以跳转到指定的页面?

我假设如果有答案,它可能是针对Adobe的PDF阅读器插件或其他某些软件版本有限制的,但我更感兴趣的是这种技术是否存在。

5个回答

79

是的,您可以通过数字或命名位置链接到特定页面,并且如果用户的浏览器使用Adobe Reader作为查看PDF文件的插件,则始终有效。

要链接到特定页码,请使用:

<a href="http://www.domain.com/file.pdf#page=3">Link text</a>

针对已命名的位置(目标):

<a href="http://www.domain.com/file.pdf#nameddest=TOC">Link text</a>

使用Acrobat在PDF中创建目录:

  1. 手动浏览PDF,找到所需位置
  2. 转到"视图">"导航选项卡">"目录"
  3. 在选项下,选择"扫描文档"
  4. 完成后,在选项菜单中选择"新建目录"并输入适当的名称

16
重要提示:命名目标不是书签。您可以使用Adobe Acrobat(完整版,而非阅读器!)及其导航面板“目标”添加命名目标。我不知道如何直接链接到书签。没有记录的URL参数。 - eFloh
我知道这是一个老问题。但我想知道是否有人知道如何在使用.NET代码构建PDF时向PDF添加命名目标。我们正在使用Dynamic PDF组件在.NET中创建我们的PDF。Dynamic PDF不支持添加命名目标。 - mortb
1
它不支持相对引用,例如somedir/my.pdf#page=3,以及PDF-XChange Viewer(通过MS Office Professional Plus 2010 / 14.0.7116.5000另存为..pdfmy.docx创建) - Andreas Covidiot
2
似乎一个简单的锚点标记对于“书签”来说是有效的,至少对于Chrome v57而言。因此,像{{link1:链接文本}}这样的链接对于Chrome v57(或更高版本,我想)是有效的。 - Kemal Erdogan

17

RFC 3778第3节规定了可以与PDF文件一起使用的“片段标识符”,其中包括nameddest和page。


14

有多个查询参数可以处理。 完整列表如下:

来源

+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| Syntax                  | Description                                                                                  | Example                                              |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| nameddest=destination   | Specifies a named destination in the PDF document                                            | http://example.org/doc.pdf#Chapter6                  |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| page=pagenum            | Specifies a numbered page in the document, using an integer                                  | http://example.org/doc.pdf#page=3                    |
|                         | value. The document’s first page has a pagenum value of 1.                                   |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| comment=commentID       | Specifies a comment on a given page in the PDF document. Use                                 | #page=1&comment=452fde0e-fd22-457c-84aa-             |
|                         | the page command before this command.                                                        | 2cf5bed5a349                                         |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| collab=setting          | Sets the comment repository to be used to supply and store                                   | #collab=DAVFDF@http://review_server/Collab           |
|                         | comments for the document. This overrides the default comment                                | /user1                                               |
|                         | server for the review or the default preference. The setting is of the                       |                                                      |
|                         | form store_type@location, where valid values for store_type are:                             |                                                      |
|                         | ● DAVFDF (WebDAV)                                                                            |                                                      |
|                         | ● FSFDF (Network folder)                                                                     |                                                      |
|                         | ● DB (ADBC)                                                                                  |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| zoom=scale              | Sets the zoom and scroll factors, using float or integer values. For                         | http://example.org/doc.pdf#page=3&zoom=200,250,100   |
| zoom=scale,left,top     | example, a scale value of 100 indicates a zoom value of 100%.                                |                                                      |
|                         | Scroll values left and top are in a coordinate system where 0,0                              |                                                      |
|                         | represents the top left corner of the visible page, regardless of                            |                                                      |
|                         | document rotation                                                                            |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| view=Fit                | Set the view of the displayed page, using the keyword values                                 | http://example.org/doc.pdf#page=72&view=fitH,100     |
| view=FitH               | defined in the PDF language specification. For more information,                             |                                                      |
| view=FitH,top           | see the PDF Reference.                                                                       |                                                      |
| view=FitV               | Scroll values left and top are floats or integers in a coordinate                            |                                                      |
| view=FitV,left          | system where 0,0 represents the top left corner of the visible                               |                                                      |
| view=FitB               | page, regardless of document rotation.                                                       |                                                      |
| view=FitBH              | Use the page command before this command.                                                    |                                                      |
| view=FitBH,top          |                                                                                              |                                                      |
| view=FitBV              |                                                                                              |                                                      |
| view=FitBV,left         |                                                                                              |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| viewrect=left,top,wd,ht | Sets the view rectangle using float or integer values in a                                   |                                                      |
|                         | coordinate system where 0,0 represents the top left corner of the                            |                                                      |
|                         | visible page, regardless of document rotation.                                               |                                                      |
|                         | Use the page command before this command.                                                    |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| pagemode=bookmarks      | Displays bookmarks or thumbnails.                                                            | http://example.org/doc.pdf#pagemode=bookmarks&page=2 |
| pagemode=thumbs         |                                                                                              |                                                      |
| pagemode=none           |                                                                                              |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| scrollbar=1|0           | Turns scrollbars on or off                                                                   |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| search=wordList         | Opens the Search panel and performs a search for any of thewords in the specified word list. | #search="word1 word2"                                |
|                         | The first matching word ishighlighted in the document.                                       |                                                      |
|                         | The words must be enclosed in quotation marks and separated byspaces.                        |                                                      |
|                         | You can search only for single words. You cannot search for a string of words.               |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| toolbar=1|0             | Turns the toolbar on or off.                                                                 |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| statusbar=1|0           | Turns the status bar on or off.                                                              |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| messages=1|0            | Turns the document message bar on or off.                                                    |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| navpanes=1|0            | Turns the navigation panes and tabs on or off.                                               |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| highlight=lt,rt,top,btm | Highlights a specified rectangle on the displayed page. Use the                              |                                                      |
|                         | page command before this command.                                                            |                                                      |
|                         | The rectangle values are integers in a coordinate system where                               |                                                      |
|                         | 0,0 represents the top left corner of the visible page, regardless of                        |                                                      |
|                         | document rotation                                                                            |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+
| fdf=URL                 | Specifies an FDF file to populate form fields in the PDF file beingopened.                   | #fdf=http://example.org/doc.fdf                      |
|                         | Note: The fdf parameter should be specified last in a URL.                                   |                                                      |
+-------------------------+----------------------------------------------------------------------------------------------+------------------------------------------------------+

很高兴你找到了完整的文档,@Matas。但是难道没有更新的文档吗?这个已经大约10年了... - Greg Dubicki
2
@GregDubicki 你好 Greg,我认为不可能有新的 PDF,除非他们发布新类型的 PDF(例如 PDFX)......这取决于处理 URL 的机制在哪里,我想。 - Matas Vaitkevicius

8
值得一提的是,Wayne的解决方案 在以下浏览器中均有效
  • Chrome (自2011年v. 14起,详见此问题)(在v. 87和v. 44上测试通过),
  • Firefox(在v. 84.0.1和v. 40上测试通过),
  • Opera(在v. 73和v. 31上测试通过),
  • Safari(在v. 14.0.2上测试通过,但在v. 8上未能成功),

(更新至2021年1月最新版本。)


你有关于IE如何处理pdf深层链接的任何信息吗? - TeeJaay
不好意思,@TeeJaay,我的电脑上没有IE来测试它。 - Greg Dubicki

7

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接