Get started with canvg CDN

MIT licensed

Canvg: library for converting chart types between Google Charts and Canvas.

Tags:
  • javascript
  • client
  • browser
  • svg
  • canvas

Stable version

Copied!

How to start using canvg CDN


// Include the Canvg library from the CDN
const Canvg = require('https://cdn.cdnhub.io/canvg/4.0.1/umd.js');

// Create a source SVG string
const svgString = `
  <svg width="100" height="100">
    <circle cx="50" cy="50" r="40" fill="red" />
  </svg>
`;

// Create a new canvas element
const canvas = document.createElement('canvas');
canvas.width = 100;
canvas.height = 100;
document.body.appendChild(canvas);

// Use Canvg to render the SVG string to the canvas
const context = canvas.getContext('2d');
new Canvg(context, svgString);

// Log the canvas to the console for demonstration
console.log(canvas.toDataURL());

All versions