<div id="content-to-convert" style="width: 772px;color: #000000;">
生成图片内容
</div>
html2canvas(document.getElementById('content-to-convert'), { scale: 2}).then(canvas => {
// html2canvas(document.getElementById('content-to-convert')).then(canvas => {
const img = new Image();
img.src = canvas.toDataURL();
this.imgs = img.src
// 跳转窗口
//const previewWindow = window.open('', '_blank');
//previewWindow.document.write(`<img src="${img.src}" />`);
// this.pr(this.imgs)
const style = `@page { size: auto; margin: 0; } img { width: 500px; }`; // 设置图片宽度为 500px,你可以根据实际需求调整这个值
printJS({
printable: img.src,
type: 'image',
header: '',
targetStyles: [],
scanStyles: false,
style
});
});
标签:src,canvas,vue,const,img,打印,生成,html2canvas,document
From: https://blog.csdn.net/qq_34631220/article/details/142464291