简体   繁体   English

fabric.js不使用SVG文件导出Canvas

[英]fabric.js not exporting Canvas with SVG file

I'm trying to import an SVG file to my canvas using the fabric.js API. 我正在尝试使用fabric.js API将SVG文件导入画布。

The rendering works but when I try to export (toSVG()) my canvas I get an empty output. 渲染有效,但是当我尝试导出(toSVG())我的画布时,我得到一个空输出。

Here is how I add my SVG file to the canvas (rendering works): 这是我将SVG文件添加到画布的方式(渲染方式):

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 使用Fabric.js 1.4.0创建

Any help would be most welcome. 任何帮助将是最欢迎的。

fabricSVGFromURL is asynchronous. fabricSVGFromURL是异步的。 So when you call canvas.toSVG() , nothing has been added to the canvas yet. 因此,当您调用canvas.toSVG() ,尚未将任何内容添加到画布。

You need to call canvas.toSVG() inside the callback. 您需要在回调内调用canvas.toSVG()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM