解决print.js打印html2canvas转换的图片时,两页以上会多出一页空白页

需求

谷歌浏览器打印指定页面元素,先转成图片再打印,发现两页以上就会多出一页空白页

解决

打印图片的时候设置下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}`,
        });
      });

猜你喜欢

转载自blog.csdn.net/qq_42611074/article/details/130408333