在 Chrome/Firefox 中打印到 pdf 时,当锚标记的任何子项具有 position:absolute 时,HTML 链接会丢失

HTML Links are lost during print to pdf in Chrome/Firefox when any children of anchor tag has position:absolute

提问人:Aravinth Chellathurai 提问时间:3/8/2023 更新时间:3/8/2023 访问量:130

问:

在 Chrome 和 Firefox 中打印到 PDF 转换期间,超链接丢失。

我也尝试使用 Chromium 无头浏览器从 HTML 创建 PDF,并观察到相同的行为。

重现问题的步骤:

(1) 创建一个带有标签的 HTML 文件 (2) 创建任意标签

或样式中包含“position:absolute”的标记。 (3) 将HTML文件打印为PDF

示例 HTML 代码段:

<html>
<body>
    <a href="https://www.google.com">
        <p style="position: absolute;"> Hello </p>
    </a>
</body>
</html>
html pdf

评论


答:

0赞 kojow7 3/8/2023 #1

如果您尝试在块级段落中使用锚元素,它可能更适合您:

<html>
<body>
<p style="position: absolute;">
    <a href="https://www.google.com">
         Hello
    </a>
</p>
</body>
</html>

评论

0赞 Aravinth Chellathurai 7/31/2023
感谢您的评论。但是,我有一个用例,可以在锚标记中包含“position: absolute;”。