Skip to content

Instantly share code, notes, and snippets.

@runeb
Created August 25, 2011 14:34
Show Gist options
  • Save runeb/1170801 to your computer and use it in GitHub Desktop.
Save runeb/1170801 to your computer and use it in GitHub Desktop.
Export the paper.js view as SVG by rendering to http://svgkit.sourceforge.net/web/SVGCanvas.html
// SVGCanvas.prototype.transform = SVGCanvas.prototype.translate;
// SVGCanvas.prototype.fillText = SVGCanvas.prototype.text;
paper.View.prototype.toSVG = function() {
var svgContext = new SVGCanvas(this.canvas.width, this.canvas.height);
var oldCtx = this._context;
this._context = svgContext;
this.draw(false);
this._context = oldCtx;
// Optional serialization of the SVG DOM nodes
var serializer = new XMLSerializer();
return serializer.serializeToString(svgContext.svg.htmlElement);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment