0

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

Nami12
  • 5
  • 1
  • 3

1 Answers1

1

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');
Vanquished Wombat
  • 9,075
  • 5
  • 28
  • 67