Nami12
Nami12

Reputation: 5

Convert Konva-Canvas into PDF using React-Konva

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

Upvotes: 0

Views: 967

Answers (1)

Vanquished Wombat
Vanquished Wombat

Reputation: 9545

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');

Upvotes: 1

Related Questions