dom转成图片再使用print.js打印,一旦打印2页或以上就有空白页
检测过图片是正常的,打印的预览就不正常了。
正常的
加了几行后,超过了一页,第一页就是空白页
代码:
toImg() {
const dom = document.querySelector('.printContent')
dom.style.height = 'auto'
dom.style.overflow = 'visible'
// 转图片打印
html2canvas(dom, {
backgroundColor: null,
useCORS: true,
windowHeight: document.body.scrollHeight
}).then(canvas => {
const url = canvas.toDataURL()
const styles = '@page {size: auto;}'
printJS({
printable: url,
type: 'image',
documentTitle: '文档模板',
style: styles
})
})
}
图片没问题,说明dom没问题,就是打印出了问题,网上都说调margin和height,但在这里好像没用。
尝试使用@page的margin,更加证明样式没问题。
@page {
margin-top: -200px
}
跪求大佬。。。。。