使用 React-Konva 将 Konva-Canvas 转换为 PDF

发布于 2025-01-14 16:38:26 字数 410 浏览 2 评论 0原文

你好,我已经实现了如何以 png 和 jpeg 格式保存画布,但我想将其保存为 pdf 我已经从这里看到了 JavaScript 代码:https://konvajs.org/docs/sandbox/Canvas_to_PDF.html 我想知道如何在React中实现 这是我的演示代码: https://codesandbox.io/s/react-canvas -n779q2?file=/src/App.js

Hello i have implemented on how to save the canvas in png and jpeg but i would like to save it into pdf i have seen the code for JavaScript from here:https://konvajs.org/docs/sandbox/Canvas_to_PDF.html
i would like to know how it can be implemented in React
here is my demo code:
https://codesandbox.io/s/react-canvas-n779q2?file=/src/App.js

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

思念绕指尖 2025-01-21 16:38:26

您所需要的只是 Konva Stage 的参考。然后你可以这样做:

var pdf = new jsPDF('l', 'px', [stage.width(), stage.height()]);
pdf.addImage(
  stage.toDataURL({ pixelRatio: 2 }),
  0,
  0,
  stage.width(),
  stage.height()
);

pdf.save('canvas.pdf');

All you need is a reference to the Konva Stage. Then you can do:

var pdf = new jsPDF('l', 'px', [stage.width(), stage.height()]);
pdf.addImage(
  stage.toDataURL({ pixelRatio: 2 }),
  0,
  0,
  stage.width(),
  stage.height()
);

pdf.save('canvas.pdf');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文