如何添加URL以作为可点击链接工作?
我正在使用React-PDF库生成PDF。 一切似乎都正常工作,但是我无法从 @react-pdf/Renderer中制作链接
元素以正常工作。
const add_hyperlink = (url_text: string) => {
return <Text><Link src={url_text}>{url_text}</Link></Text>;
};
在PDF文档中,它看起来像是一个链接,甚至指针在悬停时都会更改,单击链接时,在Chrome中没有发生任何事情,而在Adobe Reader中,它会导致安全块。
我尝试使用&lt; a&gt;
标签,但导致相同的输出。 有人知道如何解决这个问题吗?谢谢。
编辑: 我在研究此研究时意识到的事情。注意,因为很容易与微小的差异混淆。
- Library
@React-PDF/Renderer
用于在React中创建PDF。 - Library
React-PDF
用于在React应用中显示现有的PDF。
关于使用注释选项的一些提及,包括“导入'react-pdf/dist/page/annotationlayer.css';“
,使链接适当地显示了许多开发人员。但是,这属于React-PDF库,只有在需要将PDF呈现在React-App中时才有效。
在这种情况下,我正在使用@react-pdf/Renderer
创建一个新的PDF,但是我正在生成一个链接来下载生成的PDF文件( https://react-pdf.org/advanced#on-the-fly-the-fly-rendering )。
我也找到了解决问题的解决方案。 我使用的链接应该重定向到另一个URL,因此问题。我使用了SRC中的最终链接,然后它运行顺利。
我希望这些观察将来对某人有帮助:)
I am generating a pdf using react-pdf library.
Everything seems to be working fine but I can't make the Link
element from @react-pdf/renderer to work properly.
const add_hyperlink = (url_text: string) => {
return <Text><Link src={url_text}>{url_text}</Link></Text>;
};
In the pdf document, it appears as a link should and even the pointer changes on hover, on clicking the link, in chrome nothing happens, while in adobe reader, it results in a security block.
I tried to use an <a>
tag instead, but it resulted in the same output.
Does someone know how to resolve this? Thanks.
EDIT:
Something I realized while researching on this. Noting down because it is easy to get confused with the tiny differences.
- library
@react-pdf/renderer
is used to create pdfs in react. - library
react-pdf
is used to display existing pdf in a react app.
There were several mentions about using annotation options and including "import 'react-pdf/dist/Page/AnnotationLayer.css';"
which made links appear properly for many developers. However this belongs to react-pdf library and will only work if it is needed to render pdf within the react-app.
In this case, I am creating a new PDF with @react-pdf/renderer
but I am generating a link to download the generated PDF file (https://react-pdf.org/advanced#on-the-fly-rendering).
I found the solution to my problem as well.
The link I was using is supposed to redirect to another url, and hence the problem. I used the final link in src and then it works smooth.
I hope these observations are of help to someone in the future :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)