在React中发布文本和图像给PDF
我正在尝试创建一个博客文章网站,任何人都可以发布任何内容。而且,任何用户都可以一次点击下载任何帖子。因此,是否可以实现一个按钮,以下载除侧菜单除外并在React中发表评论以外的整个特定帖子内容。
I'm trying to create a blog post website where anyone can post anything. And also any user can download any post in one click. So is it possible to implement a button for download whole specific post content except side menus and comment in react.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您想让用户能够下载博客文章(React组件)为PDF。
查看 robin wieruch
您基本上要做的是创建参考对于您的组件,然后使用HTML2Canvas NPM软件包将其转换为画布,然后将其转换为图像数据。
使用PDFJS NPM软件包将图像数据添加到PDF中并下载。
有关详细信息,请参见链接。
I assume you want to give the user the ability to download a blog post (react component) as pdf.
Check out this tutorial by Robin Wieruch
What you basically do is create a ref for your component and then convert it to a canvas with html2canvas npm package, then to image data.
The image data is added to a pdf with pdfjs npm package and downloaded.
See the link for details.