wewin打印机 vue版本 直接用
思路:
建议:
1、打印的东西组合在页面上
2、使用htmlcavas将模块输出成图片
3、将图片调整 将之作为打印内容
代码
const handlePrint = async () => {await nextTick();const dom = document.getElementById("print-area");if (!dom) {ElMessage.error("找不到打印区域");return;}const canvas = await html2canvas(dom, {backgroundColor: "#fff",scale: 2,useCORS: true,});const imgData = canvas.toDataURL("image/png");const wps = new WewinPrintService();const label = new wps.Label();label.labelWidth = 100; // 单位:毫米label.labelHeight = 80;const imgBlock = new wps.GraphicBlock();imgBlock.path = imgData;imgBlock.x = 0;imgBlock.y = 0;imgBlock.width = 80; // 宽高单位:mm(旋转后注意调换)imgBlock.height = 100;imgBlock.rotate = 90;label.blocks = [imgBlock];const printerName = "WEWIN";wps.SetPrinter([label], printerName, function () {wps.Print([label]);});
};