문제

I'm using paper.js and I want to make a button to download a snapshot of the canvas at any point. Paper.js has an exportSVG function that will return either an SVGSVGElement or a string with SVG code. How can I make a button that will simply download this into a screenshot.svg file for the user?

In other words, How can I cause a browser to create a file to download from a string or SVGSVGElement?

도움이 되었습니까?

해결책

I solved this with FileSaver:

var svg = paper.project.exportSVG({asString: true});
var blob = new Blob([svg], {type: "image/svg+xml;charset=utf-8"});
saveAs(blob, 'image.svg');
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top