0

我正在使用html2Canvas库并尝试使用以下代码制作 SVG 的屏幕截图:

var svgElements= $container.find('svg');
svgElements.each(function (){
    var canvas, xml;

    canvas = document.createElement("canvas");
    canvas.className = "screenShotTempCanvas";
    //convert SVG into a XML string
    xml = (new XMLSerializer()).serializeToString(this);
    xml = xml.replace(/xmlns=\"http:\/\/www\.w3\.org\/2000\/svg\"/, '');
    canvg(canvas, xml);
    $(canvas).insertAfter(this); 

    this.className"tempHide";
    $(this).hide();
}); 
$container.find('.screenShotTempCanvas').remove(); 
$container.find('.tempHide').show().removeClass('tempHide');

但我的问题是我在 svg 中有一个输入(foreignObject)。它拍摄的屏幕截图仅包含 svg 元素。有人对此有解决方案吗?如何捕获页面上的所有元素?

感谢!

4

0 回答 0