修改源码:自定义宽高
var width = options.width != null ? options.width : node.ownerDocument.defaultView.innerWidth;
var height = options.height != null ? options.height : node.ownerDocument.defaultView.innerHeight;
return renderDocument(node.ownerDocument, options, width, height, index).then(function (canvas) {**
if (typeof(options.onrendered) === "function") {
log("options.onrendered is deprecated, html2canvas returns a Promise containing the canvas");
options.onrendered(canvas);
}
return canvas;
});
调用:
var height = $('#htmlcanvas').outerHeight(true);
if(height <= 650 || height>=1024){height += 53;}//适配
html2canvas($("#htmlcanvas"),{
height:height,
// window.devicePixelRatio是设备像素比
// dpi: 192,//放大像素(2倍),以免图片模糊
dpi: window.devicePixelRatio,
}).then(function(....)}