1
我想一个html字符串转换为类似的图像,以它是如何在这里完成: html2canvas creates a canvas with a width and height of zero?渲染HTML字符串,但不显示HTML本身以帆布
不过我不想表现出比对结果图像的任何其他这一页。因此,我不能简单地将html字符串添加到DOM中,就像在那里建议的那样。我想我想要实现的是可能的,因为html2canvas test console就是这样做的。
我试图产生空的结果如下:
var doc = document.implementation.createHTMLDocument();
doc.open();
doc.write("<html><header></header><body><div>test</div></body></html>");
doc.close();
html2canvas(doc.body, {
onrendered:function(newCanvas) {
document.body.appendChild(newCanvas);
}
});
<script src="https://github.com/niklasvh/html2canvas/blob/master/dist/html2canvas.js"></script>
任何人都可以提出这样做的方式是什么?