Search code examples
svgjointjs

Save jointjs diagram drawn on paper, which can be rendered to paper to edit


Working on jointjs diagrams on paper. I am able to download the diagram drawn on a paper using following code:

var svgDoc = paper.svg;
var serializer = new XMLSerializer();
var svgString = serializer.serializeToString(svgDoc);

Now I want to save this svg on server, which can be rendered again to paper so that I can edit it and save again.

Is it possible in jointjs?


Solution

  • Nope. SVG import is not possible in JointJS. The way you should do it is to export the diagram into JSON and than import it back:

    var json = JSON.stringify(graph);
    // send the json to the server, store to DB or whatever....
    
    // ... later on...
    
    // load back the json to the diagram:
    graph.fromJSON(JSON.parse(json))
    

    See http://jointjs.com/api#joint.dia.Graph:toJSON