【问题标题】:Puppeteer link (<a>) is not converted from html to pdfPuppeteer 链接 (<a>) 未从 html 转换为 pdf
【发布时间】:2022-01-17 10:54:41
【问题描述】:

我正在使用 Puppeteer 将一些 html 转换为 pdf。我尝试转换的一些 html 的一个非常基本的示例如下所示:

<div>
   Link: <a href="test">test</a>
</div>

但是,我注意到这个 html 实际上不会被转换为 pdf 文件中的链接。奇怪的是,它获得了链接的样式,但实际上并不是 pdf 中的可点击链接(它只是纯文本)。下图是它的渲染结果:

当悬停在“测试”文本上时,光标也不是指针。

此问题的原因可能是什么?是否有解决方法?

【问题讨论】:

  • 您找到解决方案了吗?
  • @SaaranshMenon 是的,如果我没记错的话,我必须在链接前面加上 https:// 。之后它就起作用了。

标签: javascript node.js pdf-generation puppeteer


【解决方案1】:

来自https://www.w3schools.com/tags/att_a_href.asp

如果 href 属性不存在,则标签不会是 超链接。

提示:您可以使用 href="#top" 或 href="#" 链接到顶部 当前页面!

您的链接样式设置为一个链接test,但 "test" 是在一条无路可走的道路上(它不是一个有效的地址或 URL 链接,所以只会坐在那里思考你想让它做什么。)

&lt;a href="URL"&gt;

URL The URL of the link.
Possible values:

An absolute URL - points to another web site (like href="https://www.example.com/default.htm")
A relative URL - points to a file within a web site (like href="default.htm")
Link to an element with a specified id within the page (like href="#section2")
Other protocols (like http://, ftp://, mailto:, file://, etc..)
A script (like href="javascript:alert('Hello');")

放置另一个位置,例如 &lt;h2 id="test"&gt;Go 2&lt;/h2&gt;

那么 Link: &lt;a href="#test"&gt;Hyper test&lt;/a&gt;

将跳转到“Go 2”

或用于外部位置

那么 Link: &lt;a href="https://webAddress"&gt;Hyper test&lt;/a&gt;

【讨论】:

    猜你喜欢
    • 2019-08-11
    • 1970-01-01
    • 2016-03-17
    • 1970-01-01
    • 2016-12-01
    • 2019-10-25
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    相关资源
    最近更新 更多