html2canvas截图打印

import printJS from 'print-js';
import html2canvas from 'html2canvas';

export const mapPrint = {

    defaultDomId: "printDiv",

    print(domId) {
        const that = this;
        if (!domId) {
            domId = that.defaultDomId;
        }
        that.beforePrint();
        html2canvas(document.getElementById(domId)).then(canvas => {
            const imageData = canvas.toDataURL("image/jpeg", 1);
            that._print(imageData);
        });
    },


    beforePrint() {
        // TODO
    },

    _print(imageData) {
        const that = this;
        printJS({
            printable: imageData,
            type: 'image',
            documentTitle: '&nbsp'
        });
        that.afterPrint();
    },

    afterPrint() {
        // TODO
    },

};

版权声明:本文为beijing20110905原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。