需求
谷歌浏览器打印指定页面元素,先转成图片再打印,发现两页以上就会多出一页空白页
解决
打印图片的时候设置下style属性,设置body{margin:0}}
html2canvas(this.$refs.table, {
width: this.$refs.table.clientWidth,
height: this.$refs.table.clientHeight,
}).then((canvas) => {
const url = canvas.toDataURL();
printjs({
printable: url,
type: 'image',
documentTitle: '打印图片',
maxWidth: 9999,
style: `body{margin:0}`,
});
});