svgsaver
download an svg element as an SVG or PNG file, including CSS defined styles.
Features
- Download
<svg>
by element object or css selectors. - Copies SVG element styles as rendered in the browser, including styles defined in CSS stylesheets.
- Copies only SVG relevant and non-default styles. See here.
Usage
For maximum compatibility across browsers include eligrey/FileSaver.js/ and eligrey/canvas-toBlob.js.
Example
var SvgSaver = require('svgsaver'); // if using CommonJS environment
var svgsaver = new SvgSaver(); // creates a new instance
var svg = document.querySelector('#mysvg'); // find the SVG element
svgsaver.asSvg(svg); // save as SVG
Demos
- http://bl.ocks.org/Hypercubed/db9e99d761f90d87cf43
- http://bl.ocks.org/Hypercubed/58fff7215e53d6565f32
Acknowledgments
Based on previous work on Hypercubed/angular-downloadsvg-directive. Some portions of this code inspired by raw and moagrius/copycss.