有没有办法添加“替代文本” Adobe Acrobat 中 PDF 中的链接?

发布于 2024-08-02 06:38:34 字数 244 浏览 7 评论 0原文

在 Adob​​e Acrobat Pro 中,向页面添加链接并不困难,但我想知道是否还有一种方法可以向链接添加“替代文本”(有时称为“标题文本”)。在 HTML 中,可以这样完成:

<a href="url" title="Text goes here">link</a>

然后,当鼠标悬停在链接上时,文本将显示为一个小工具提示。有 PDF 的等效项吗?如果是这样,你如何添加它?

In Adobe Acrobat Pro, it's not that difficult to add links to a page, but I'm wondering if there's also a way to add "alt text" (sometimes called "title text") to links as well. In HTML, this would be done as such:

<a href="url" title="Text goes here">link</a>

Then when the mouse is hovering over the link, the text appears as a little tooltip. Is there an equivalent for PDFs? And if so, how do you add it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

流云如水 2024-08-09 06:38:34

实际上 PDF 确实支持替代文本。它是逻辑结构记录的 PDF 参考 1.7 第 10.8.2 节“替代描述”的一部分

/Span << /Lang(en-us)/Alt(六点星)>> BDC (✡) Tj EMC

Actually PDF does support alternate text. It's part of Logical Structure documented PDF Reference 1.7 section 10.8.2 "Alternate Descriptions"

/Span << /Lang (en-us) /Alt (six-point star) >> BDC (✡) Tj EMC

不即不离 2024-08-09 06:38:34

在 PDF 语法中,链接注释支持内容条目作为备用描述:

/Annots [
  <<
    /Type /Annot
    /Subtype /Link
    /Border [1 1 1]
    /Dest [4 0 R /XYZ 0 0 null]
    /Rect [ 50 50 80 60 ]
    /Contents (Link)
  >>
]

引用“PDF 参考 - 第 6 版 - Adob​​e® 便携式文档格式 - 版本 1.7 - 2006 年 11 月” ”:

Contents 文本字符串(可选) 要为注释显示的文本,或者,如果此类注释不显示文本,则为注释内容的替代描述人类可读的形式。无论哪种情况,在提取文档内容以支持残障用户的可访问性或用于其他目的时,此文本都很有用

稍后:

对于所有其他注释类型(Link、Movie、Widget、PrinterMark 和 TrapNet),内容条目以人类可读的方式提供注释内容的替代表示形式表格

这是当存在边框时,Sumatra PDF v3.1.2 可以很好地显示:
输入图片此处描述

然而,其他 PDF 阅读器并未广泛支持此功能。

W3C 在其 WCAG 2.0 的 PDF 技术中推荐了另一种显示替代方案的方法用于辅助功能的链接上的文本:

In PDF syntax, Link annotations support a Contents entry to serve as an alternate description:

/Annots [
  <<
    /Type /Annot
    /Subtype /Link
    /Border [1 1 1]
    /Dest [4 0 R /XYZ 0 0 null]
    /Rect [ 50 50 80 60 ]
    /Contents (Link)
  >>
]

Quoting "PDF Reference - 6th edition - Adobe® Portable Document Format - Version 1.7 - November 2006" :

Contents text string (Optional) Text to be displayed for the annotation or, if this type of annotation does not display text, an alternate description of the annotation’s contents in human-readable form. In either case, this text is useful when extracting the document’s contents in support of accessibility to users with disabilities or for other purposes

And later on:

For all other annotation types (Link , Movie , Widget , PrinterMark , and TrapNet), the Contents entry provides an alternate representation of the annotation’s contents in human-readable form

This is displayed well with Sumatra PDF v3.1.2, when a border is present:
enter image description here

However this is not widely supported by other PDF readers.

The W3C, in its PDF Techniques for WCAG 2.0 recommend another ways to display alternative texts on links for accessibility purposes:

败给现实 2024-08-09 06:38:34

不可以,无法将替代文本添加到 PDF 中的链接。 PDF 参考中没有对此做出规定。

与此相关的是,PDF 中的链接和 HTML 文档中的链接的处理方式完全不同。 PDF 中的链接实际上是一种注释,位于页面顶部的指定坐标处,与文档中的文本或图像没有技术关系。 HTML 文档中的链接与它们超链接的元素有直接关系。

No, it's not possible to add alt text to a link in a PDF. There's no provision for this in the PDF reference.

On a related note, links in PDFs and links in HTML documents are handled quite differently. A link in a PDF is actually a type of annotation, which sits on top of the page at specified co-ordinates, and has no technical relationship to the text or image in the document. Where as links in HTML documents bare a direct relationpship to the elements which they hyperlink.

陈甜 2024-08-09 06:38:34

替代文本或替代文本与标题文本不同。标题文本是供人类消费的元数据。替代文本是媒体上的替代文本内容,以防媒体加载失败。

Alt text, or alternate text, is not the same as title text. Title text is meta data intended for human consumption. Alt text is alternate text content upon media in case the media fails to load.

星光不落少年眉 2024-08-09 06:38:34

还有一个技巧,使用不可见的表单按钮,该按钮不执行任何操作,但允许在鼠标悬停在其上方时添加一个小的弹出工具提示文本。

There is also a trick using an invisible form button that doesn't do anything but allows a small popup tooltip text to be added when the mouse hovers over it.

來不及說愛妳 2024-08-09 06:38:34

正式地,根据 ISO 32000-1 14.9.3 中定义的 PDF 1.7(请参阅 Adob​​e 网站免费下载相当于 PDF 1.7 的 ISO 标准的文档),将为注释提供替代文本 - 例如链接注释 - 通过将键“Contents”添加到其数据结构并提供替代文本作为该键的文本字符串值。

不幸的是,Acrobat 似乎没有提供用户界面来添加或编辑链接注释的“内容”文本字符串,即使它存在,也不会用于工具提示。相反,工具提示似乎始终是链接注释的目标,至少在它指向 URL 时是这样。

因此,在视觉层面上,人们可以通过在具有所需行为的链接注释区域顶部添加一些其他不可见元素来解决此问题。这不是一个很好的技巧,至少对我来说是这样。此外,它对 PDF 的可访问性没有帮助,因为它引入了另一个杂散对象......

Officially, per PDF 1.7 as defined in ISO 32000-1 14.9.3 (see Adobe website for a free download of a document that is equivaent to the ISO standard for PDF 1.7), one would provide alternate text for an annotation - like for example a Link annotation - by adding a key "Contents" to its data structure and provide the alt text as a text string value for that key.

Unfortunately Acrobat does not seem to provide a user interface to add or edit this "Contents" text string for Link annotations, and even if it is present it will not be used for the tool tip. Instead the tool tip always seems to be the target of the Link annotation, at least if it points to a URL.

So on a visual level one could hack around this by adding some other invisible elements on top of the area of the Link annotation that have the desired behavior. Not a very nice hack, at least for my taste. In addition it does not help with accessibility of the PDF, as it introduces yet another stray object...

離人涙 2024-08-09 06:38:34

面对同样的问题,我使用了JS lib“pdf-lib”(https:// /pdf-lib.js.org/docs/api/classes/pdfdocument) 编辑 pdf 文件的内容并添加注释上缺少的属性。

    const pdfLib = require('pdf-lib');
    const fs = require('fs');

    function getNewMap(pdfDoc, str){
      return pdfDoc.context.obj(
       {
        Alt: new pdfLib.PDFString(str),
        Contents: new pdfLib.PDFString(str)
      }).dict;
    }

    const pdfData = await fs.readFile('your-pdf-document.pdf');
    const pdfDoc = await pdfLib.PDFDocument.load(pdfData);
    pdfDoc.context.enumerateIndirectObjects().forEach(_o => {
      const pdfRef = _o[0];
      const pdfObject = _o[1];
      if (typeof pdfObject?.lookup === "function"){
        if (pdfObject.lookup(pdfLib.PDFName.of('Type'))?.encodedName === "/Annot"){
          // We use the link URI to implement annotation "Alt" & "Contents" attributes
          const annotLinkUri = pdfObject.lookup(pdfLib.PDFName.of('A')).get(pdfLib.PDFName.of('URI')).value;
          const titleFromUri = annotLinkUri.replace(/(http:|)(^|\/\/)(.*?\/)/g, "").replace(/\//g, "").trim();
          // We build the new map with "Alt" and "Contents" attributes and assign it to the "Annot" object dictionary
          const newMap = getNewMap(pdfDoc, titleFromUri);
          const newdict = new Map([...pdfObject.dict, ...newMap]);
          pdfObject.dict = newdict;
        }
      }
    })

    // We save the file
    const pdfBytes = await pdfDoc.save();
    await fs.promises.writeFile("your-pdf-document-accessible.pdf", pdfBytes);

Facing the same problem I used the JS lib "pdf-lib" (https://pdf-lib.js.org/docs/api/classes/pdfdocument) to edit the content of the pdf file and add the missing attributes on annotations.

    const pdfLib = require('pdf-lib');
    const fs = require('fs');

    function getNewMap(pdfDoc, str){
      return pdfDoc.context.obj(
       {
        Alt: new pdfLib.PDFString(str),
        Contents: new pdfLib.PDFString(str)
      }).dict;
    }

    const pdfData = await fs.readFile('your-pdf-document.pdf');
    const pdfDoc = await pdfLib.PDFDocument.load(pdfData);
    pdfDoc.context.enumerateIndirectObjects().forEach(_o => {
      const pdfRef = _o[0];
      const pdfObject = _o[1];
      if (typeof pdfObject?.lookup === "function"){
        if (pdfObject.lookup(pdfLib.PDFName.of('Type'))?.encodedName === "/Annot"){
          // We use the link URI to implement annotation "Alt" & "Contents" attributes
          const annotLinkUri = pdfObject.lookup(pdfLib.PDFName.of('A')).get(pdfLib.PDFName.of('URI')).value;
          const titleFromUri = annotLinkUri.replace(/(http:|)(^|\/\/)(.*?\/)/g, "").replace(/\//g, "").trim();
          // We build the new map with "Alt" and "Contents" attributes and assign it to the "Annot" object dictionary
          const newMap = getNewMap(pdfDoc, titleFromUri);
          const newdict = new Map([...pdfObject.dict, ...newMap]);
          pdfObject.dict = newdict;
        }
      }
    })

    // We save the file
    const pdfBytes = await pdfDoc.save();
    await fs.promises.writeFile("your-pdf-document-accessible.pdf", pdfBytes);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文