How to get SVG object from Viewer?


#1

Is it possible to get SVG as an object from Viewer? I only found using canvas._svg but this is accessing private variable of canvas. Is there any other way?


#2

You may try Viewer#saveSVG which serves exactly your purpose. The following should work:

var bpmnJS = new BpmnViewer(...);

bpmnJS.importXML(someXML);

bpmnJS.saveSVG(function(err, svg) {
  // do stuff with the SVG
});

#3

This is something that I want to avoid. I already have saveXML that switches between modeler and viewer. Also, I’m not sure how this will affect SVG that is already rendered on the canvas.


#4

Why would you like to avoid it?


#5

Because currently I have code like this.

modelerEventBus.on("import.done", function () {
	modeler.saveXML({format: false}, function (error, xml) {
		viewer.importXML(xml, function () {
			adjustWorkflowDiagramDimensions(viewer);
			highlightAdHocWorkflowActiveTasks(viewer);
		});
	});
});

I don’t want to complicate even further this functions with saveSVG


#6

All right then :wink:.