React PDF 渲染、SSR 或客户端到服务器

发布于 2025-01-11 02:34:37 字数 841 浏览 0 评论 0原文

谁能推荐一种使用图像和字体渲染 pdf 的方法,最好使用 React?我的目标是在我的反应前端中按下按钮后,渲染带有公司徽标图像和动态 html 表格的自定义 pdf。理想情况下,PDF 在服务器端呈现,然后将文件附加到电子邮件中发送给客户。

我一直在使用 React-PDF/Renderer 但服务器端渲染有无尽的 webpack 问题。我可以让它使用字体和图像进行渲染 这里在一个独立的应用程序中,但不是在我的具有独立前端和后端的完整应用程序中,捆绑的js抱怨无法获取危险的本地路径:images/logo.png及其任何人的猜为为什么。所以我正在寻找更好的解决方案...我当前的解决方案是通过 python 脚本将图像分层到 PDF 上,但我不想这样做。

谁知道将一些简单的 HTML 渲染成 pdf 是如此复杂...我考虑过的另一种方法是通过 Google App Script (GAS) 将表格所需的信息提供给具有模板的 Google 文档,但这似乎也是不必要的复杂的。一定有一些我通过 Vite (以避免 webpack)或 Next.JS (以避免 React-pdf/renderer)缺少的解决方案......

另一种方法可能是渲染带有 React-PDF/Render 的 pdf 客户端,因为该库是更可靠的客户端,但我不知道如何将 pdf 附加到将发送的电子邮件中...我将其流式传输到服务器,在前端渲染后发送?是否可以在客户端完成这一切而不向客户端显示渲染的 pdf?

Can anyone recommend a method to render a pdf with images and fonts, preferably with React? My goal is to render a custom pdf with an image of a company logo and a dynamic html table, once a button is pressed in my react frontend. Ideally the PDF is rendered on the server side, then the file is attached to an email to be sent to the customer.

I have been using React-PDF/Renderer but server side rendering has endless webpack issues. I can get it to render with fonts and images here in a stand alone app, but not in my full app with the seperate front and back ends, the bundled js complains Cannot fetch dangerous local path: images/logo.png and its anyone's guess as to why. So I'm looking for a better solution... my current solution is to just layer the image onto the PDF after through a python script, but I'd prefer not to do this.

Who knew rendering some simple HTML into a pdf was so complex... another method I've considered is to feed the needed information for the table to a Google Doc with a template through Google App Script (GAS), but that also seems needlessly complex. There must be some solution I'm missing through Vite (to avoid webpack) or Next.JS (to avoid react-pdf/renderer)...............

Another approach might be to render the pdf client side with React-PDF/Render since that library is more reliable client side, but I don't know how I would attach the pdf to an email that would be sent off... Do I stream it to the server, after being rendered on the frontend, to be sent? Can it all be done client side without displaying the rendered pdf to the client?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文