简体   繁体   English

如何在html2canvas中将dom作为svg下载?

[英]How to download dom as svg in html2canvas?

how can I save a dom as svg file using html2canvas ? 如何使用html2canvas将dom保存为svg文件? For downlading as png , I've done something like below : 对于下垂为png,我做了如下操作:

html2canvas(document.querySelector('#demo')).then(function(canvas) {
                saveAs(canvas.toDataURL(), 'image.png');
});

How can I achieve similar result to save it as svg file ? 如何将其保存为svg文件达到相似的结果?

You don't. 你不知道

The reason you can export to png/jpg/etc is that the canvas is a pixel graphic presentation layer, so for convenience it knows how to generate the browser-supported image types that use embedded bitmaps. 可以导出到png / jpg / etc的原因是画布是像素图形表示层,因此为了方便起见,它知道如何生成使用嵌入式位图的浏览器支持的图像类型。

If you want vector graphics instead, then you'll need to actually draw vectors, and that means not relying on the canvas APIs. 如果要使用矢量图形,则实际上需要绘制矢量,这意味着不依赖canvas API。 You either roll your own vector drawing instruction set (directly generating SVG yourself, or rasterizing objects to the canvas purely as presentation layer), which I would recommend against, or you use one of several vector graphics packages already out there like Paper.js, Three.js, Rafael, and so forth. 我建议不要使用自己的矢量绘图指令集(直接自己生成SVG,或将对象光栅化为画布作为显示层),或者使用已经存在的几种矢量图形包之一,例如Paper.js, Three.js,Rafael等。

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

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