SVG download like minimal blob

Thanks for getting the minimal blob example working. I am using it to export pngs. I tried setting the type to:
type: “image/svg+xml” but this just returns a png.

Any ideas how I can implement the same kind of functionality with the svg output?


Do you mean GoJS Making SVG -- Northwoods Software ?

Almost. I need to initiate a download.

You just need to call Diagram.makeSvg instead of Diagram.makeImageData, convert the SVG DOM to a string, make a Blob out of it, and then call the same myCallback function that the Minimal Blob sample does.

  function makeBlob() {
    var svgstr = myDiagram.makeSvg({ scale: 1, background: "white" }).outerHTML;
    var blob = new Blob([svgstr], { type: "image/svg+xml" });

And remember to use “.svg” as the file type for the file name, instead of the “.png” used in the original sample.

That’s it!
Thanks again!

We’ll add a cleaned-up version of this sample in version 1.7.5, including getting it to work in IE. (Internet Explorer does not support .outerHTML on SVGSVGElement.)

The sample will be Minimal SVG Download.