Reputation: 637
I'm trying to import an SVG file to my canvas using the fabric.js API.
The rendering works but when I try to export (toSVG()) my canvas I get an empty output.
Here is how I add my SVG file to the canvas (rendering works):
fabric.loadSVGFromURL('svg/1000.svg', function(objects, options) {
//group elements
var obj = fabric.util.groupSVGElements(objects, options);
// put object on the canvas
canvas.add(obj).renderAll();
});
console.log(canvas.toSVG());
Here is the output I get:
<?xml version="1.0" encoding="UTF-8" standalone="no" ?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
Created with Fabric.js 1.4.0
Any help would be most welcome.
Upvotes: 1
Views: 1635
Reputation: 1344
fabricSVGFromURL
is asynchronous. So when you call canvas.toSVG()
, nothing has been added to the canvas yet.
You need to call canvas.toSVG()
inside the callback.
Upvotes: 2