简体   繁体   English

在反应中将文本和图像发布到 pdf

[英]Posts text and image to pdf in 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.那么是否可以实现一个按钮来下载整个特定的帖子内容,除了侧边菜单和反应中的评论。

I assume you want to give the user the ability to download a blog post (react component) as pdf.我假设您想让用户能够将博客文章(反应组件)下载为 pdf。

Check out this tutorial by Robin Wieruch查看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.您基本上要做的是为您的组件创建一个 ref,然后使用 html2canvas npm package 将其转换为 canvas,然后转换为图像数据。

The image data is added to a pdf with pdfjs npm package and downloaded.图片数据用pdfjs添加到一个pdf npm package 并下载。

See the link for details.有关详细信息,请参阅链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM