dendrofen / react-konva-to-svg

Extend Konva's functionality to export stages as SVG. Enhance the quality of exported images with SVG format.
https://dendrofen.github.io/react-konva-to-svg/
MIT License
13 stars 1 forks source link
canvas canvas-api konva nextjs react-konva react-konva-export react-konva-to-svg react-konva-utils svg svg-canvas

react-konva-to-svg

Extend Konva's functionality to export stages as SVG. Enhance the quality of exported images with SVG format.

GitHub License Build Size Version Downloads

Features

Table of Contents

Installation

You can install react-konva-to-svg using npm, yarn, or directly from GitHub.

Usage

To use react-konva-to-svg, import the library and utilize the exportStageSVG function with your Konva stage object. This function allows you to customize the export process.

exportStageSVG(stage, blob, options)

Example usage:

import { exportStageSVG } from 'react-konva-to-svg';

// Example usage
const stage = /* your Konva stage */;
const result = await exportStageSVG(stage, false, {
  onBefore: ([stage, layer]) => {
    // Perform actions before export
  },
  onAfter: ([stage, layer]) => {
    // Perform actions after export
  },
});

Compatibility Notice

Node or group does not rendering properly

If some of nodes, or any group does not rendering properly - use node caching for incorrect rendered node withing onBefore function.

Demo

Explore a live demo of react-konva-to-svg in action: Demo